Skip to main content
The sail.tinker helpers let you drive Sail inference from a Tinker RL or training loop. They bridge Tinker’s token-level sampling interface to Sail’s raw-token Responses path, so rollouts run against Sail-hosted models (optionally with a LoRA adapter) while logprobs flow back into your training code.
These helpers require tinker-cookbook installed alongside sail. Constructing a SailTokenCompleter without tinker-cookbook available raises sail.InferenceError.

sail.SailTokenCompleter

A Tinker TokenCompleter backed by Sail’s raw-token Responses API: each call sends the prompt token ids via the raw_prompt_tokens request parameter, which skips server-side chat templating and tokenization and forwards the ids verbatim to the model. Construct one with a model and sampling settings, then await it on tokenized prompts to get sampled tokens and their logprobs.

Constructor

Passing both lora and tinker_lora_signed_url, or setting tinker_lora_signed_url without adapter_config, raises ValueError.

async __call__(model_input, stop=None)

  • model_input: must expose a callable .to_ints() returning the prompt token ids (this is Tinker’s ModelInput). A non-callable to_ints, a non-integer token, or an empty prompt raises TypeError/ValueError.
  • stop: optional stop condition. An int is wrapped as a single-element list; a tuple is converted to a list; other values pass through unchanged.
Returns a Tinker TokensWithLogprobs: If the Sail response is malformed (missing or non-integer token data, or mismatched token and logprob lengths), a sail.InferenceError is raised with the offending response attached as exc.response.

get_tinker_checkpoint_signed_url_async

Resolves a Tinker checkpoint path to a signed archive URL, suitable for passing as tinker_lora_signed_url to SailTokenCompleter. It resolves the path against the Tinker service client and returns the signed URL. This helper is async-only and requires a Tinker service client with async checkpoint-URL support. Raises sail.InferenceError if the Tinker client does not provide async checkpoint URL methods, or if the response does not contain a URL.

sail.TinkerSandbox

Runs tinker-cookbook sandbox workloads on a Sailbox. It implements the cookbook’s sandbox interface, so recipes that take a sandbox execute their rollout commands in an isolated Sailbox instead of on the training machine. Each instance wraps one Sailbox for its whole life.

Constructor

Requires tinker-cookbook; constructing without it installed raises ImportError.

async run_command(command, workdir=None, timeout=60, max_output_bytes=None)

Runs a shell command and returns the cookbook’s SandboxResult.
  • command: the shell command string, run through bash.
  • workdir: directory to run in.
  • timeout: seconds before the command is killed; a killed command is reported with metrics["timed_out"] set.
  • max_output_bytes: keeps the first bytes of each output stream, the part the cookbook’s parsers read. Without it the full output is kept, up to a large safety ceiling.
A terminated or lost Sailbox raises the cookbook’s SandboxTerminatedError; other errors from the Sailbox are reported as a result with exit code -1.

async read_file(path, max_bytes=None, timeout=60)

Reads a file into the result’s stdout, within timeout seconds; without max_bytes the whole file is kept, up to a large safety ceiling. A missing or unreadable file is reported as a result with exit code 1 rather than raised, and so is a read that runs out of time.

async write_file(path, content, executable=False, timeout=60)

Writes a file into the Sailbox, within timeout seconds; executable=True marks it executable. A write that runs out of time is reported as a result with exit code 1.

async send_heartbeat(timeout=30)

Checks the sandbox’s lifetime budget. A Sailbox stays alive without keep-alives, so the heartbeat sends nothing; it only terminates the Sailbox and raises the cookbook’s SandboxTerminatedError once timeout_seconds has elapsed. timeout is part of the cookbook’s heartbeat signature and is unused here, since there is no request for it to bound.

async cleanup()

Terminates the backing Sailbox. Safe to call more than once.

tinker_sandbox_factory

Creates a TinkerSandbox for a tinker-cookbook environment. Pass this function, or a functools.partial of it to preset the keyword arguments, wherever the cookbook accepts a sandbox factory. Being a module-level function, it pickles by reference, so it survives the cookbook’s process boundaries. The registry image or Dockerfile must produce a Debian- or Ubuntu-based filesystem. Raises ImportError without tinker-cookbook installed, and a ValueError when image_ref, the task.toml image, and the environment’s Dockerfile are all absent.