Skip to main content

hanzo-train

Tinker-shaped Python client for the Hanzo Engine training API.

It mirrors the shapes of Thinking Machines' tinker SDK, so training loops written against tinker port across unchanged, while using Hanzo-canonical field names. The transport is synchronous httpx with no retries; the four training ops return a completed future exposing .result(timeout=None) so fut.result() code ports 1:1.

Install

pip install hanzo-train

Quickstart

from hanzo_train import ServiceClient, LoraConfig, AdamParams, SamplingParams, Datum, ModelInput

sc = ServiceClient(base_url="http://localhost:1234", api_key=None)   # api_key -> Authorization: Bearer

tc = sc.create_lora_training_client(
    "HuggingFaceTB/SmolLM2-135M", lora_config=LoraConfig(rank=16), wait=True, timeout=600.0
)
# wait=True polls the client until status is ready (raises on failed); wait=False returns immediately.

out = tc.forward_backward([
    {"prompt": "2+2=", "completion": "4"},
    Datum(model_input=ModelInput(tokens=[1, 2, 3]), target_tokens=[2, 3, 4], weights=[0.0, 1.0, 1.0]),
]).result()
# out.loss, out.num_tokens, out.metrics

tc.optim_step(AdamParams(lr=1e-4)).result()

resp = tc.sample(
    prompt="2+2=", sampling_params=SamplingParams(max_tokens=8, temperature=0.0), num_samples=1
).result()
# resp.sequences[0].tokens / .text

saved = tc.save_weights_and_get_sampling_client(name="my-adapter").result()   # .path, .format == "peft"
# alias: tc.save_weights(name="my-adapter")

info = tc.get_info()          # TrainingClientInfo incl. loss_history
sc.list_training_clients()    # list[TrainingClientInfo]
tc.delete()

Errors

Every non-2xx response raises HanzoTrainError(status, message):

  • 400 — bad input
  • 404 — unknown training client id
  • 409 — client still loading, or failed to load

API

ServiceClient(base_url, api_key=None)

  • create_lora_training_client(base_model, lora_config=None, wait=True, timeout=600.0, poll_interval=1.0) -> TrainingClient
  • list_training_clients() -> list[TrainingClientInfo]
  • close()

TrainingClient

  • forward_backward(data) -> Future[ForwardBackwardResult] — data items are either {"prompt": str, "completion": str} dicts or Datum values.
  • optim_step(adam_params=None) -> Future[OptimResult]
  • sample(prompt=None, tokens=None, sampling_params=None, num_samples=1) -> Future[SampleResult] — pass exactly one of prompt or tokens.
  • save_weights_and_get_sampling_client(name, dir=None) -> Future[SaveResult] (alias: save_weights)
  • get_info() -> TrainingClientInfo
  • delete()

Metadata

Release files for hanzo-train 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for hanzo-train 0.1.1
File Size Uploaded
hanzo_train-0.1.1.tar.gz 8.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for hanzo-train 0.1.1
File Interpreter ABI Platform
hanzo_train-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 15.0 kB

Release files / hanzo_train-0.1.1.tar.gz

Download URL hanzo_train-0.1.1.tar.gz
Size 8.3 kB
Tags Source
SHA-256 checksum
How to use checksums
2a9f463db50a18477a469213ea5d37ea6f0025e781d5069e3dc18668e9695200
BLAKE2b-256 checksum
How to use checksums
2f773975f564ed6b1af1c1a2b25e5203dc94443fac8faad73b783be6db97e423
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.9

Release files / hanzo_train-0.1.1-py3-none-any.whl

Download URL hanzo_train-0.1.1-py3-none-any.whl
Size 6.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
753d14d357eb23817068a41d80f3a0a03df351aaaaca8d09facf497a0dbe9026
BLAKE2b-256 checksum
How to use checksums
40863f4523899b7c4737e0a2afe17aa84b20b18b2df788528af13908918c4ac0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.9

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page