Skip to main content

Hanzo Train — Tinker-shaped client for the Hanzo Engine training API

Project description

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()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

hanzo_train-0.1.0.tar.gz (8.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

hanzo_train-0.1.0-py3-none-any.whl (6.7 kB view details)

Uploaded Python 3

File details

Details for the file hanzo_train-0.1.0.tar.gz.

File metadata

  • Download URL: hanzo_train-0.1.0.tar.gz
  • Upload date:
  • Size: 8.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for hanzo_train-0.1.0.tar.gz
Algorithm Hash digest
SHA256 c57639f2d80d21ee73539a377d99a3a48a568bac5446f0bd8d724addd28aaa64
MD5 7b7fb6e3e951e1495317f5861091da82
BLAKE2b-256 36d5298d5f62882e17168c133497ba681fdac57dd01107286119e31eb2e31bea

See more details on using hashes here.

File details

Details for the file hanzo_train-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: hanzo_train-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for hanzo_train-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 81c299832487b9d90ae6015071e370b6b14777c0e6ffb6b09d8a4039e2b6aac4
MD5 fd415ecbfc64b709fdab24fe1d714465
BLAKE2b-256 53c852baf9de43e4ce3b2b1ea4f0fbe134598c938f64f22c7d8cb05cf9cc042c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page