Parallel fine-tuning sweep¶
Fine-tunes two models at the same time, one spot H100 job each, and saves each result to its own folder in one bucket.
View example files ↗ · Related reference: Jobs →
What this example does¶
sweep.pybuilds twoJobSpecrecipes, creates both jobs, then waits for each and prints its record. The second job is created before the first one is waited on, so they can run in parallel.configs/qwen_0_5b.yaml: QLoRA forQwen/Qwen2.5-0.5B,learning_rate: 2e-4,lora_r: 8.configs/qwen_1_5b.yaml: QLoRA forQwen/Qwen2.5-1.5B,learning_rate: 1e-4,lora_r: 16.- Both jobs mount
s3://fine-tuning-axolotlat/workspace/data, train from/workspace/data/configs/…, and copy their output tos3://fine-tuning-axolotl/output/qwen_0_5b/ands3://fine-tuning-axolotl/output/qwen_1_5b/.
Requirements¶
- A Nebius profile that can create jobs: see Install and authenticate.
- Spot quota for two H100 jobs at the same time.
- An Object Storage bucket named
fine-tuning-axolotlthat the jobs can mount read-write, and the AWS CLI with credentials for it.
Runtime and compute¶
| Jobs | 2, named axolotl-qwen-0.5b and axolotl-qwen-1.5b |
| Machine | gpu="h100" each, pricing="spot" |
| Disk | 500Gi each |
| Timeout | 24h each |
Run it¶
Upload both configs, then start the sweep from the repository root:
aws s3 cp examples/training/axolotl-sweep/configs/ \
s3://fine-tuning-axolotl/configs/ --recursive \
--endpoint-url https://storage.eu-north1.nebius.cloud
uv run python examples/training/axolotl-sweep/sweep.py
Expected output¶
Two job ids, one per create(). Then, for each job in turn, the state changes and the final record from display(). The first wait can end long after the second job finished: waiting is sequential, the jobs are not.
How to adapt it¶
- Add a model: add a config under
configs/, and aJobSpecwith its own output folder and name. - Generate the recipes in a loop when they differ only in the config path; each
create()gets its own job. - Use the batch example for the pattern with error handling and result checks.
- Evaluate each result and pick the best with the task version of this sweep.
Troubleshooting¶
- Writes to
debug.logfail on the bucket. Both configs keepoutput_dir: /workspace/outputon the local disk, because Axolotl's appends todebug.logare not supported on the S3 mount. Keep it that way in new configs. - One job waits in
PROVISIONING, or ends inERROR. The project may not have spot capacity or quota for two H100s at once. The final record shows the reason.
Source¶
sweep.py
"""Run two Axolotl fine-tunes in parallel and save adapters to one volume.
Upload ``configs/qwen_0_5b.yaml`` and ``configs/qwen_1_5b.yaml`` to
``s3://fine-tuning-axolotl/configs/`` before running. Both jobs mount that
bucket and copy checkpoints into separate folders under
``/workspace/data/output/``. Uses the active Nebius profile.
"""
import nebius_serverless as ns
IMAGE = "docker.io/axolotlai/axolotl:main-20260309-py3.11-cu128-2.9.1"
def train(config: str) -> list[str]:
"""Train one config, then copy its output to the shared volume."""
return [
"bash",
"-lc",
f"axolotl train /workspace/data/configs/{config}.yaml"
f" && mkdir -p /workspace/data/output/{config}"
" && cp -r /workspace/output/."
f" /workspace/data/output/{config}",
]
def main() -> None:
"""Create both jobs, wait for each, and display the final records."""
# The arguments both jobs share.
common = dict(
image=IMAGE,
gpu="h100",
pricing="spot",
disk="500Gi",
timeout="24h",
volumes=["s3://fine-tuning-axolotl:/workspace/data:rw"],
)
jobs = [
ns.Job(command=train(config), name=name, **common).create()
for config, name in (
("qwen_0_5b", "axolotl-qwen-0.5b"),
("qwen_1_5b", "axolotl-qwen-1.5b"),
)
]
for job in jobs:
job.wait()
job.display()
if __name__ == "__main__":
main()
configs/qwen_0_5b.yaml
base_model: Qwen/Qwen2.5-0.5B
load_in_4bit: true
adapter: qlora
datasets:
- path: Salesforce/wikitext
name: wikitext-2-raw-v1
split: "train[:2000]"
type: completion
field: text
sequence_len: 128
micro_batch_size: 1
gradient_accumulation_steps: 1
learning_rate: 2e-4
max_steps: 30
val_set_size: 0
logging_steps: 5
# Keep training output local, then copy to bucket after training.
output_dir: /workspace/output
lora_r: 8
lora_alpha: 16
lora_dropout: 0.05
lora_target_modules:
- q_proj
- k_proj
- v_proj
- o_proj
- gate_proj
- up_proj
- down_proj
configs/qwen_1_5b.yaml
base_model: Qwen/Qwen2.5-1.5B
load_in_4bit: true
adapter: qlora
datasets:
- path: Salesforce/wikitext
name: wikitext-2-raw-v1
split: "train[:2000]"
type: completion
field: text
sequence_len: 128
micro_batch_size: 1
gradient_accumulation_steps: 2
learning_rate: 1e-4
max_steps: 30
val_set_size: 0
logging_steps: 5
# Keep training output local, then copy to bucket after training.
output_dir: /workspace/output
lora_r: 16
lora_alpha: 32
lora_dropout: 0.05
lora_target_modules:
- q_proj
- k_proj
- v_proj
- o_proj
- gate_proj
- up_proj
- down_proj