| name | tinker-types |
| description | Reference for Tinker SDK types — Datum, ModelInput, TensorData, SamplingParams, response types, error types, and helper functions. Use when the user needs to build training data, construct model inputs, understand response objects, or handle errors. |
Tinker SDK Types
Quick reference for the core types used throughout the Tinker SDK and cookbook.
Reference
Read docs/api-reference/types.md for the complete type reference.
Core data types
Type hierarchy
Datum
├── model_input: ModelInput (list of chunks)
│ ├── EncodedTextChunk (token IDs)
│ └── ImageChunk (vision inputs)
└── loss_fn_inputs: dict[str, TensorData]
└── TensorData (numpy/torch wrapper)
ModelInput
from tinker import ModelInput
mi = ModelInput.from_ints([1, 2, 3, 4, 5])
tokens = mi.to_ints()
length = mi.length
mi2 = mi.append(chunk)
mi3 = mi.append_int(42)
mi_empty = ModelInput.empty()
TensorData
from tinker import TensorData
td = TensorData.from_numpy(np.array([1.0, 0.0, 1.0]))
td = TensorData.from_torch(torch.tensor([1.0, 0.0]))
arr = td.to_numpy()
tensor = td.to_torch()
lst = td.tolist()
Datum
from tinker import Datum, ModelInput, TensorData
datum = Datum(
model_input=ModelInput.from_ints(tokens),
loss_fn_inputs={"weights": TensorData.from_numpy(weights_array)},
)
Configuration types
SamplingParams
from tinker import SamplingParams
params = SamplingParams(
max_tokens=256,
temperature=1.0,
top_k=50,
top_p=0.95,
stop=["<|eot_id|>"],
seed=42,
)
AdamParams
from tinker import AdamParams
adam = AdamParams(
learning_rate=2e-4,
beta1=0.9,
beta2=0.95,
eps=1e-12,
weight_decay=0.0,
grad_clip_norm=1.0,
)
LoraConfig
from tinker import LoraConfig
config = LoraConfig(
rank=32,
seed=None,
train_mlp=True,
train_attn=True,
train_unembed=True,
)
Response types
ForwardBackwardOutput
Returned by forward_backward() and forward():
result = tc.forward_backward(data=batch, loss_fn="cross_entropy")
result.metrics
result.loss_fn_outputs
result.loss_fn_output_type
SampleResponse / SampledSequence
Returned by sample():
response = sc.sample(prompt=mi, num_samples=4, sampling_params=params)
response.sequences
response.prompt_logprobs
response.topk_prompt_logprobs
for seq in response.sequences:
seq.tokens
seq.logprobs
seq.stop_reason
Other response types
OptimStepResponse — confirms parameter update
SaveWeightsResponse — path: str (tinker:// path to saved weights)
LoadWeightsResponse — confirms loaded weights
GetInfoResponse — model_data: ModelData (model_name, lora_rank, tokenizer_id)
GetServerCapabilitiesResponse — supported_models: list[SupportedModel]
WeightsInfoResponse — base_model, lora_rank, is_lora, train_mlp, train_attn, train_unembed
Checkpoint and run types
from tinker import TrainingRun, Checkpoint, CheckpointType, ParsedCheckpointTinkerPath
run.training_run_id
run.base_model
run.is_lora
run.lora_rank
run.last_checkpoint
run.user_metadata
ckpt.checkpoint_id
ckpt.checkpoint_type
ckpt.tinker_path
ckpt.size_bytes
ckpt.public
ckpt.expires_at
parsed = ParsedCheckpointTinkerPath.from_tinker_path("tinker://run-id/weights/ckpt-id")
parsed.training_run_id
parsed.checkpoint_type
parsed.checkpoint_id
Error types
All exceptions inherit from tinker.TinkerError:
APIError → APIStatusError: BadRequestError (400), AuthenticationError (401), PermissionDeniedError (403), NotFoundError (404), ConflictError (409), UnprocessableEntityError (422), RateLimitError (429), InternalServerError (500+)
APIConnectionError, APITimeoutError, APIResponseValidationError
RequestFailedError — async request failure with error category
Cookbook helper functions
Use these instead of manual Datum construction:
tinker_cookbook.supervised.data.conversation_to_datum(messages, renderer, max_length, train_on_what) — full SL pipeline
tinker_cookbook.supervised.common.datum_from_model_input_weights(model_input, weights, max_length) — from ModelInput + weights
renderer.build_supervised_example(messages) — returns (ModelInput, weights)
Common pitfalls
- Use helper functions instead of manual dict construction for Datum
TensorData wraps arrays — don't pass raw numpy/torch directly to loss_fn_inputs
ModelInput.from_ints() expects a flat list of integers, not nested lists
ModelInput.length is a property, not a method
- Handle
tinker.RateLimitError in production code with exponential backoff