mergekit
swaleio/[email protected]
mergekit
Runs mergekit-yaml <config> <output_dir>: merges the weights of two or more
models into one with 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.
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. 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 in the Swale documentation.
Licensed under the MIT License.