Generate synthetic chain-of-thought data
Source on GitHub: the workflows/synthetic-reasoning-data folder, with its README and its workflow file.
Builds a reasoning dataset for fine-tuning. A reasoning model solves each question step by step; a second model, the judge, compares each solution's final answer with the reference answer; and the solutions judged correct are kept as chat-format training rows. Solutions that ran out of tokens before finishing are not judged.
| Step | Task definition | Compute |
|---|---|---|
| Fetch the generator, and the judge, in parallel | swaleio/hf-download | cpu-4 |
| Write one solve request per question | swaleio/duckdb | cpu-4 |
| Solve | swaleio/vllm-batch | a100-1 |
| Join solutions to questions, count unfinished ones, write one judge request per finished solution | swaleio/duckdb | cpu-4 |
| Judge | swaleio/vllm-batch | a100-1 |
Keep the correct solutions as messages rows | swaleio/duckdb | cpu-4 |
Upload to the Hugging Face Hub, when hub_repo is set | swaleio/hf-upload | cpu-4 |
The Compute column gives each step's compute type, the compute its tasks are allocated.
Every step is its own task. The two GPU steps load different models, so each holds a GPU only for its own pass.
Inputs
| Input | Default | Description |
|---|---|---|
generator | Qwen/Qwen3-1.7B | Model that solves, reasoning inside <think> tags. |
judge | Qwen/Qwen3-8B | Model that checks each final answer; it answers correct or incorrect only. |
questions | the train split of openai/gsm8k | Parquet file or glob, as a DuckDB path. |
question_column | question | Column holding each question. |
answer_column | answer | Column holding each reference answer. |
limit | 500 | Number of questions. |
max_tokens | 4096 | Longest solution, reasoning included. |
hub_repo | empty | Hugging Face dataset repo to upload reasoning-sft.parquet to, as data/train.parquet. |
The downloads and the upload read the secret hf_token.
Output
reasoning-sft.parquet on the workspace: a messages column of user question
and assistant solution, the format swaleio/trl-sft trains on.
solutions.parquet keeps every solution with its finish_reason.
Run it
You need the CLI, logged in to your account, and a project to add the workflow to; Getting started sets them up.
-
Save the file under The workflow file as
workflow.yaml, and add it to a project:swale workflow create --project-name my-project --file workflow.yamlThe command prints
Workflow created:followed by the workflow's ID. -
The workflow reads the secret
hf_token. Create it as a project secret, or as an account secret that allows the project, as Use secrets in workflows shows. -
Start a run with the workflow's ID:
swale workflow run start --project-name my-project --workflow-id <workflow-id>Each input you leave out takes its default from Inputs, and
--input <name>=<value>gives it another value.
Create and manage workflows covers the other ways to add a workflow, Start and manage workflow runs how to follow a run, and View and stream task logs how to read its tasks' logs.
The workflow file
Workflow definition syntax describes each key in it.
name: Generate synthetic chain-of-thought data
description: Has a reasoning model solve math questions step by step and a judge model check each answer, and keeps the correct solutions as a fine-tuning dataset.
compute_type: cpu-4
inputs:
generator:
description: Hugging Face repo id of the model that writes the solutions. Qwen3 models reason inside <think> tags before they answer.
default: Qwen/Qwen3-1.7B
judge:
description: Hugging Face repo id of the model that checks each final answer against the reference.
default: Qwen/Qwen3-8B
questions:
description: Parquet file or glob holding the questions and reference answers, as a DuckDB path.
default: hf://datasets/openai/gsm8k/main/train-*.parquet
question_column:
description: Column holding each question.
default: question
answer_column:
description: Column holding each reference answer. For GSM8K the final number follows ####.
default: answer
limit:
description: Number of questions to solve.
default: "500"
max_tokens:
description: Longest solution, in tokens, reasoning included.
default: "4096"
hub_repo:
description: Hugging Face dataset repo to upload the kept solutions to, as namespace/name. Leave empty to keep them on the workspace only.
default: ""
entry_point: main
blocks:
main:
tasks:
fetch_generator:
name: Fetch generator
uses: swaleio/hf-download
args:
repo: ${{inputs.generator}}
dest: ${{env.WORKFLOW_STORAGE}}/generator
token: ${{secrets.hf_token}}
fetch_judge:
name: Fetch judge
uses: swaleio/hf-download
args:
repo: ${{inputs.judge}}
dest: ${{env.WORKFLOW_STORAGE}}/judge
token: ${{secrets.hf_token}}
requests:
name: Write solve requests
uses: swaleio/duckdb
args:
sql: |
CREATE TABLE questions AS
SELECT 'q-' || lpad((row_number() OVER () - 1)::VARCHAR, 6, '0') AS custom_id,
"${{inputs.question_column}}" AS question,
"${{inputs.answer_column}}" AS reference
FROM (SELECT * FROM '${{inputs.questions}}' LIMIT ${{inputs.limit}});
COPY questions TO '${{env.WORKFLOW_STORAGE}}/questions.parquet' (FORMAT parquet);
COPY (
SELECT custom_id, 'POST' AS method, '/v1/chat/completions' AS url,
{'model': '${{env.WORKFLOW_STORAGE}}/generator',
'messages': [{'role': 'user', 'content': question || '\n\nSolve this step by step and give the final answer on the last line.'}],
'max_tokens': ${{inputs.max_tokens}},
'temperature': 0.6, 'top_p': 0.95} AS body
FROM questions
) TO '${{env.WORKFLOW_STORAGE}}/solve-requests.jsonl' (FORMAT json);
solve:
name: Solve
uses: swaleio/vllm-batch
compute_type: a100-1
start_on:
- fetch_generator
- requests
args:
model: ${{env.WORKFLOW_STORAGE}}/generator
input_file: ${{env.WORKFLOW_STORAGE}}/solve-requests.jsonl
output_file: ${{env.WORKFLOW_STORAGE}}/solutions.jsonl
judge_requests:
name: Write judge requests
uses: swaleio/duckdb
start_on:
- solve
args:
sql: |
CREATE TABLE solutions AS
SELECT q.*,
r.response.body.choices[1].message.content AS solution,
r.response.body.choices[1].finish_reason AS finish_reason
FROM '${{env.WORKFLOW_STORAGE}}/questions.parquet' q
JOIN read_json('${{env.WORKFLOW_STORAGE}}/solutions.jsonl') r USING (custom_id);
COPY solutions TO '${{env.WORKFLOW_STORAGE}}/solutions.parquet' (FORMAT parquet);
COPY (
SELECT custom_id, 'POST' AS method, '/v1/chat/completions' AS url,
{'model': '${{env.WORKFLOW_STORAGE}}/judge',
'messages': [{'role': 'user', 'content':
'Question:\n' || question ||
'\n\nReference answer:\n' || reference ||
'\n\nProposed solution (only its final answer matters):\n' ||
regexp_replace(solution, '(?s)^.*</think>', '') ||
'\n\nIs the final answer of the proposed solution the same as the reference answer? Answer correct or incorrect.'}],
'max_tokens': 8, 'temperature': 0,
'chat_template_kwargs': {'enable_thinking': false},
'structured_outputs': {'choice': ['correct', 'incorrect']}} AS body
FROM solutions
WHERE finish_reason = 'stop'
) TO '${{env.WORKFLOW_STORAGE}}/judge-requests.jsonl' (FORMAT json);
SELECT finish_reason, count(*) AS solutions FROM solutions GROUP BY ALL;
judge:
name: Judge
uses: swaleio/vllm-batch
compute_type: a100-1
start_on:
- fetch_judge
- judge_requests
args:
model: ${{env.WORKFLOW_STORAGE}}/judge
input_file: ${{env.WORKFLOW_STORAGE}}/judge-requests.jsonl
output_file: ${{env.WORKFLOW_STORAGE}}/verdicts.jsonl
keep:
name: Keep correct solutions
uses: swaleio/duckdb
start_on:
- judge
args:
sql: |
CREATE TABLE judged AS
SELECT s.*, trim(v.response.body.choices[1].message.content) AS verdict
FROM '${{env.WORKFLOW_STORAGE}}/solutions.parquet' s
JOIN read_json('${{env.WORKFLOW_STORAGE}}/verdicts.jsonl') v USING (custom_id);
SELECT verdict, count(*) AS solutions FROM judged GROUP BY ALL;
COPY (
SELECT custom_id,
[{'role': 'user', 'content': question},
{'role': 'assistant', 'content': solution}] AS messages
FROM judged WHERE verdict = 'correct' ORDER BY custom_id
) TO '${{env.WORKFLOW_STORAGE}}/reasoning-sft.parquet' (FORMAT parquet);
publish:
name: Upload when asked
start_on:
- keep
if:
condition: ${{inputs.hub_repo}}
true: upload
upload:
tasks:
upload_dataset:
name: Upload to the Hugging Face Hub
uses: swaleio/hf-upload
args:
repo: ${{inputs.hub_repo}}
repo_type: dataset
source: ${{env.WORKFLOW_STORAGE}}/reasoning-sft.parquet
path_in_repo: data/train.parquet
token: ${{secrets.hf_token}}
Licenses of the defaults
- Models: Qwen/Qwen3-1.7B and Qwen/Qwen3-8B, Apache-2.0.
- Dataset: openai/gsm8k, MIT.