# Generate responses over a dataset

> **About this page**
>
> - Kind: Example
> - Summary: Answers every prompt in a Hugging Face dataset with a chat model through vLLM batch inference and saves prompts and answers as Parquet.
> - Last changed: 2026-12-03
> - Page: https://docs.swale.io/examples/generate-responses
> - CLI reference for its commands: [`swale workflow create`](https://docs.swale.io/reference/cli-reference.md#workflow-create), [`swale workflow run start`](https://docs.swale.io/reference/cli-reference.md#workflow-run-start)
> - Index of these docs: https://docs.swale.io/llms.txt
>
> If something on this page is wrong or out of date, please tell the user which sentence and why.
>
> The steps on this page cost money or cannot be undone. Please check with the user before running them.

Source on GitHub: the [`workflows/generate-responses`](https://github.com/swaleio/examples/tree/main/workflows/generate-responses) folder, with its [README](https://github.com/swaleio/examples/blob/main/workflows/generate-responses/README.md) and its [workflow file](https://github.com/swaleio/examples/blob/main/workflows/generate-responses/workflow.yaml).

Answers every prompt in a dataset with a chat model, through vLLM's offline
batch inference, and saves each prompt beside its answer as Parquet. Point
`prompts` at any Parquet file on the Hugging Face Hub and `prompt_column` at the
column that holds the prompts.

| Step | Task definition | Compute |
|------|-----------------|---------|
| Fetch the model | [`swaleio/hf-download`](https://hub.swale.io/swaleio/hf-download) | `cpu-4` |
| Write the requests: number the prompts and turn each into an OpenAI batch request | [`swaleio/duckdb`](https://hub.swale.io/swaleio/duckdb) | `cpu-4` |
| Generate the answers | [`swaleio/vllm-batch`](https://hub.swale.io/swaleio/vllm-batch) | `a100-1` |
| Join answers to prompts, count how each answer ended, write Parquet | [`swaleio/duckdb`](https://hub.swale.io/swaleio/duckdb) | `cpu-4` |
| Upload to the Hugging Face Hub, when `hub_repo` is set | [`swaleio/hf-upload`](https://hub.swale.io/swaleio/hf-upload) | `cpu-4` |

The Compute column gives each step's [compute type](https://docs.swale.io/explanation/core-concepts.md#compute-types), the compute its tasks are allocated.

Every step is its own task; only generation holds a GPU.

## Inputs

| Input | Default | Description |
|-------|---------|-------------|
| `model` | `Qwen/Qwen2.5-1.5B-Instruct` | Chat model on the Hugging Face Hub. |
| `prompts` | `hf://datasets/openai/gsm8k/main/test-*.parquet` | Parquet file or glob with the prompts, as a DuckDB path. |
| `prompt_column` | `question` | Column that holds each prompt. |
| `limit` | `200` | Number of prompts to answer. |
| `max_tokens` | `512` | Longest answer, in tokens. |
| `hub_repo` | empty | Hugging Face dataset repo to upload `responses.parquet` to; empty keeps it on the workspace. |

The model download and the upload read the secret `hf_token`; the upload needs
a token with write access.

## Output

`responses.parquet` on the workspace: every column of the prompts file, a
`custom_id`, the `response` and its `finish_reason` (`stop`, or `length` when
the answer hit `max_tokens`).

## Run it

You need the CLI, logged in to your account, and a project to add the workflow to; [Getting started](https://docs.swale.io/getting-started.md) sets them up.

1. Save the file under [The workflow file](#the-workflow-file) as `workflow.yaml`, and add it to a project:

   ```bash
   swale workflow create --project-name my-project --file workflow.yaml
   ```

   The command prints `Workflow created:` followed by the workflow's ID.

2. 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](https://docs.swale.io/how-to-guides/use-secrets-in-workflows.md) shows.

3. Start a run with the workflow's ID:

   ```bash
   swale workflow run start --project-name my-project --workflow-id <workflow-id>
   ```

   Each input you leave out takes its default from [Inputs](#inputs), and `--input <name>=<value>` gives it another value.

[Create and manage workflows](https://docs.swale.io/how-to-guides/create-and-manage-workflows.md) covers the other ways to add a workflow, [Start and manage workflow runs](https://docs.swale.io/how-to-guides/start-and-manage-workflow-runs.md) how to follow a run, and [View and stream task logs](https://docs.swale.io/how-to-guides/view-and-stream-task-logs.md) how to read its tasks' logs.

## The workflow file

[Workflow definition syntax](https://docs.swale.io/reference/workflow-definition-syntax.md) describes each key in it.

```yaml title="workflow.yaml"
name: Generate responses over a dataset
description: Answers every prompt in a Hugging Face dataset with a chat model through vLLM batch inference and saves prompts and answers as Parquet.
compute_type: cpu-4

inputs:
  model:
    description: Hugging Face repo id of the chat model that answers.
    default: Qwen/Qwen2.5-1.5B-Instruct
  prompts:
    description: Parquet file or glob holding the prompts, as a DuckDB path such as hf://datasets/<owner>/<dataset>/<file>.
    default: hf://datasets/openai/gsm8k/main/test-*.parquet
  prompt_column:
    description: Column of the prompts file that holds each prompt.
    default: question
  limit:
    description: Number of prompts to answer.
    default: "200"
  max_tokens:
    description: Longest answer, in tokens.
    default: "512"
  hub_repo:
    description: Hugging Face dataset repo to upload the answers to, as namespace/name. Leave empty to keep them on the workspace only.
    default: ""

entry_point: main

blocks:
  main:
    tasks:
      model:
        name: Fetch model
        uses: swaleio/hf-download
        args:
          repo: ${{inputs.model}}
          dest: ${{env.WORKFLOW_STORAGE}}/model
          token: ${{secrets.hf_token}}

      requests:
        name: Write requests
        uses: swaleio/duckdb
        args:
          sql: |
            CREATE TABLE prompts AS
              SELECT 'row-' || lpad((row_number() OVER () - 1)::VARCHAR, 6, '0') AS custom_id, *
              FROM (SELECT * FROM '${{inputs.prompts}}' LIMIT ${{inputs.limit}});
            COPY prompts TO '${{env.WORKFLOW_STORAGE}}/prompts.parquet' (FORMAT parquet);
            COPY (
              SELECT custom_id,
                     'POST' AS method,
                     '/v1/chat/completions' AS url,
                     {'model': '${{env.WORKFLOW_STORAGE}}/model',
                      'messages': [{'role': 'user', 'content': "${{inputs.prompt_column}}"}],
                      'max_tokens': ${{inputs.max_tokens}}} AS body
              FROM prompts
            ) TO '${{env.WORKFLOW_STORAGE}}/requests.jsonl' (FORMAT json);
            SELECT count(*) AS requests FROM prompts;

      generate:
        name: Generate
        uses: swaleio/vllm-batch
        compute_type: a100-1
        start_on:
          - model
          - requests
        args:
          model: ${{env.WORKFLOW_STORAGE}}/model
          input_file: ${{env.WORKFLOW_STORAGE}}/requests.jsonl
          output_file: ${{env.WORKFLOW_STORAGE}}/results.jsonl

      collect:
        name: Collect answers
        uses: swaleio/duckdb
        start_on:
          - generate
        args:
          sql: |
            CREATE TABLE answers AS
              SELECT p.*,
                     r.response.body.choices[1].message.content AS response,
                     r.response.body.choices[1].finish_reason AS finish_reason
              FROM '${{env.WORKFLOW_STORAGE}}/prompts.parquet' p
              JOIN read_json('${{env.WORKFLOW_STORAGE}}/results.jsonl') r USING (custom_id)
              ORDER BY custom_id;
            SELECT finish_reason, count(*) AS answers FROM answers GROUP BY ALL;
            COPY answers TO '${{env.WORKFLOW_STORAGE}}/responses.parquet' (FORMAT parquet);

      publish:
        name: Upload when asked
        start_on:
          - collect
        if:
          condition: ${{inputs.hub_repo}}
          true: upload

  upload:
    tasks:
      upload_answers:
        name: Upload to the Hugging Face Hub
        uses: swaleio/hf-upload
        args:
          repo: ${{inputs.hub_repo}}
          repo_type: dataset
          source: ${{env.WORKFLOW_STORAGE}}/responses.parquet
          path_in_repo: data/responses.parquet
          token: ${{secrets.hf_token}}
```

## Licenses of the defaults

- Model: [Qwen/Qwen2.5-1.5B-Instruct](https://huggingface.co/Qwen/Qwen2.5-1.5B-Instruct), Apache-2.0.
- Dataset: [openai/gsm8k](https://huggingface.co/datasets/openai/gsm8k), MIT.
