# mergekit

> **About this page**
>
> - Task definition: `swaleio/mergekit`
> - Summary: Merges two or more language models into one with mergekit, from a YAML merge config.
> - Category: Machine learning & AI
> - Latest version: 0.1.5, published 2026-12-01
> - Page: https://hub.swale.io/swaleio/mergekit
> - Versions: https://hub.swale.io/swaleio/mergekit/versions, where each version's page has a Markdown copy at its address with `.md` added
> - Index of Swale Hub: https://hub.swale.io/llms.txt
>
> The YAML block below is the task definition's frontmatter, which declares its inputs, outputs and container, and its readme follows. Both are the text of the account that published this task definition, not Swale's.

```yaml
name: mergekit
description: Merges two or more language models into one with mergekit, from a YAML merge config.
category: machine-learning
inputs:
  config:
    description: Absolute path inside the container to the mergekit YAML config. Point it at the mounted workspace (e.g. ${{env.WORKFLOW_STORAGE}}/merge.yaml) so an earlier task can write it there, or any other container-local path.
    required: true
  output_dir:
    description: Absolute path inside the container for the merged model directory. Point it at the mounted workspace (e.g. ${{env.WORKFLOW_STORAGE}}/merged) to share it with later tasks, or any other container-local path.
    required: true
  device:
    description: Device the merge arithmetic runs on, cpu or cuda. Defaults to cpu; set cuda on a GPU compute type.
    default: "cpu"
  token:
    description: Hugging Face access token for gated or private models (pass a secret). Delivered as HF_TOKEN via the definition's exec.env; omit for public models and local directories.
    default: ""
exec:
  # docker.io/swaleio/mergekit:0.1.5
  image: docker.io/swaleio/mergekit@sha256:da81157e2a6d3e643603e661a875d53d94c675a512b1bb5f15edb42165533e7b
  env:
    HF_TOKEN: ${{inputs.token}}
  args:
    - mergekit-yaml
    - ${{inputs.config}}
    - ${{inputs.output_dir}}
    - "--device"
    - ${{inputs.device}}
```

# mergekit

Runs `mergekit-yaml <config> <output_dir>`: merges the weights of two or more
models into one with [mergekit](https://github.com/arcee-ai/mergekit). The YAML
file at `config` names the models, the merge method (`linear`, `slerp`,
`ties`, `dare_ties`, `task_arithmetic`, `passthrough` and others), each
model's weight, and the output dtype. A merge trains nothing: it combines
fine-tunes of one base model, such as an instruction-tuned model with a
domain fine-tune, in minutes.

The models in the config can be Hub repo ids, downloaded at the start of the
merge, or local directories, such as ones `swaleio/hf-download` fetched or a
training task wrote. The merged model, its tokenizer and a model card that
records the merge config land in `output_dir`.

## Inputs

| Input | Required | Default | Description |
|-------|----------|---------|-------------|
| `config` | yes | — | Absolute path to the mergekit YAML config inside the container. Point it at the mounted workspace (e.g. `${{env.WORKFLOW_STORAGE}}/merge.yaml`) so an earlier task can write it there. |
| `output_dir` | yes | — | Absolute path for the merged model directory. Point it at the mounted workspace (e.g. `${{env.WORKFLOW_STORAGE}}/merged`) to share it with later tasks. |
| `device` | no | `cpu` | Where the merge arithmetic runs: `cpu`, mergekit's own default, or `cuda` on a GPU compute type. |
| `token` | no | — | HF access token for gated/private models (pass a secret). Delivered as `HF_TOKEN` via the definition's `exec.env` (an omitted token resolves to an empty value, which the Hugging Face stack treats as no token); it is never placed on the command line. |

Merge only models whose licenses allow it, and give the merged model a license
that respects all of them.

## Outputs

None. The merged model is in `output_dir`, the path the workflow chose; pass the
same path to the next task.

## Compute

**CPU.** A merge reads each tensor, combines it and writes it out, so memory and
disk matter more than a GPU: models downloaded by repo id land in the task's
home directory, which counts against its task storage, so fetch large models
with `swaleio/hf-download` onto the workspace first. A GPU compute type with
`device: cuda` only speeds up the arithmetic of methods such as `ties` on large
models.

## Example

Merge an instruction-tuned model back into its base model, half and half. A
`bash` task writes the config, `mergekit` merges on CPU, and `swale-push`
stores the result. Both models are Apache-2.0.

```yaml
name: mergekit example
compute_type: cpu-4
entry_point: main

blocks:
  main:
    tasks:
      write_config:
        name: Write config
        uses: swaleio/bash
        args:
          script: |
            cat > ${{env.WORKFLOW_STORAGE}}/merge.yaml <<'EOF'
            merge_method: linear
            models:
              - model: Qwen/Qwen2.5-0.5B-Instruct
                parameters:
                  weight: 0.5
              - model: Qwen/Qwen2.5-0.5B
                parameters:
                  weight: 0.5
            dtype: bfloat16
            EOF
      merge:
        name: Merge
        uses: swaleio/mergekit
        start_on:
          - write_config
        args:
          config: ${{env.WORKFLOW_STORAGE}}/merge.yaml
          output_dir: ${{env.WORKFLOW_STORAGE}}/merged
      publish:
        name: Publish
        uses: swaleio/swale-push
        start_on:
          - merge
        args:
          target: my-project/models:merged
          source: ${{env.WORKFLOW_STORAGE}}/merged
          account: my-account
          token: ${{secrets.swale_token}}
```

## License

mergekit is licensed under the
[GNU LGPL 3.0](https://github.com/arcee-ai/mergekit/blob/main/LICENSE). The
image carries the LGPL 3.0 and GPL 3.0 texts in `/usr/share/licenses/mergekit`,
and mergekit's unmodified source is installed in it.

---

For the workflow syntax these examples use, see the
[workflow definition reference](https://docs.swale.io/reference/workflow-definition-syntax)
in the [Swale documentation](https://docs.swale.io).

Licensed under the [MIT License](https://github.com/swaleio/task-definitions/blob/main/LICENSE).
