mirror of
https://github.com/hanzo-ml/trainer.git
synced 2026-09-24 00:31:34 +00:00
Adds one transformers + PEFT + TRL ClusterTrainingRuntime per method that
fine-tunes ANY HuggingFace causal LM. The base model + dataset come from the
TrainJob's model/dataset initializers (hf:// or s3://, secretRef for private/gated
repos); every hyperparameter is read from the trainer container env that the Hanzo
Cloud broker sets. Adapters are merged into the base on completion, so one serving
path (KServe HuggingFace runtime) works for lora/qlora/full alike; output is
written to OUTPUT_DIR (the org's S3 Space when s3://).
- manifests/base/runtimes/hanzo_finetune.yaml 3 ClusterTrainingRuntimes (+kustomization)
- cmd/trainers/hanzo/finetune.py env-driven entrypoint (LoRA/QLoRA/full)
- cmd/trainers/hanzo/finetune_test.py pytest for the pure config/format helpers
- cmd/trainers/hanzo/{Dockerfile,requirements.txt,README.md}
- examples/yaml/hanzo-finetune-qlora.yaml example TrainJob (the broker's output)
kustomize build clean · ruff clean · 14 pytest pass. Image built in CI
(ghcr.io/hanzoai/finetune-runtime), not locally.
Co-authored-by: Hanzo Dev <[email protected]>
Hanzo fine-tuning trainer
The node entrypoint for the hanzo-ft-{lora,qlora,full} ClusterTrainingRuntimes
(manifests/base/runtimes/hanzo_finetune.yaml). One env-driven image fine-tunes
any HuggingFace causal LM with LoRA, QLoRA (4-bit) or full fine-tuning using
transformers + peft + trl.
How it runs
A TrainJob references a runtime (e.g. hanzo-ft-qlora) and supplies:
initializer.model.storageUri/initializer.dataset.storageUri— the base model and dataset (hf://…ors3://…). The runtime's model/dataset initializers download them to/workspace/modeland/workspace/datasetbefore this entrypoint runs. AsecretRef(thehf-tokenSecret) authenticates private or gated repos.trainer.resourcesPerNode— the GPU count.trainer.env— every hyperparameter (see the env contract infinetune.py).
The entrypoint trains, then writes a servable HuggingFace-format model to
OUTPUT_DIR (LoRA/QLoRA adapters are merged into the base, so KServe's HuggingFace
runtime can serve any method). When OUTPUT_DIR is an s3:// URI the result is
uploaded to the org's S3 Space.
Build
The image is built in CI (not locally) and pinned by the operator:
docker build . -f cmd/trainers/hanzo/Dockerfile -t ghcr.io/hanzoai/finetune-runtime:0.1.0
Test
The pure config/format helpers are unit-tested (no GPU):
cd cmd/trainers/hanzo && pytest finetune_test.py