跳到正文
cccskills
免费在 GitHub 公开

tinker-types

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.

中文简介正在准备中。当前显示原文说明。

查看安装方法

包含的文件(1)

  • SKILL.md6.6 KB

SKILL.md(原文)

安装前可以查看交给 AI 代理的指令内容。

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])  # From token list
tokens = mi.to_ints()                        # Back to list
length = mi.length                           # Token count (property)
mi2 = mi.append(chunk)                       # Append a chunk
mi3 = mi.append_int(42)                      # Append a single token
mi_empty = ModelInput.empty()                # Empty input

TensorData

from tinker import TensorData

td = TensorData.from_numpy(np.array([1.0, 0.0, 1.0]))  # From numpy
td = TensorData.from_torch(torch.tensor([1.0, 0.0]))    # From torch
arr = td.to_numpy()                                       # Back to numpy
tensor = td.to_torch()                                    # Back to torch
lst = td.tolist()                                         # Back to list
# Fields: data (flat list), dtype ("int64"|"float32"), shape (optional)

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,        # Max generation length
    temperature=1.0,       # Sampling temperature
    top_k=50,              # Top-K sampling (-1 = no limit)
    top_p=0.95,            # Nucleus sampling
    stop=["<|eot_id|>"],   # Stop sequences (strings or token IDs)
    seed=42,               # Reproducible seed
)

AdamParams

from tinker import AdamParams

adam = AdamParams(
    learning_rate=2e-4,
    beta1=0.9,             # Gradient moving average
    beta2=0.95,            # Gradient squared moving average
    eps=1e-12,             # Numerical stability
    weight_decay=0.0,      # Decoupled weight decay
    grad_clip_norm=1.0,    # Global gradient norm clipping (0.0 = disabled)
)

LoraConfig

from tinker import LoraConfig

config = LoraConfig(
    rank=32,               # LoRA rank
    seed=None,             # Initialization seed
    train_mlp=True,        # Train MLP layers
    train_attn=True,       # Train attention layers
    train_unembed=True,    # Train unembedding layer
)

Response types

ForwardBackwardOutput

Returned by forward_backward() and forward():

result = tc.forward_backward(data=batch, loss_fn="cross_entropy")
result.metrics              # dict[str, float] — training metrics (includes loss)
result.loss_fn_outputs      # list[LossFnOutput] — per-sample outputs
result.loss_fn_output_type  # str — loss output class name

SampleResponse / SampledSequence

Returned by sample():

response = sc.sample(prompt=mi, num_samples=4, sampling_params=params)
response.sequences                # list[SampledSequence]
response.prompt_logprobs          # Optional[list[Optional[float]]] — per-prompt-token logprobs
response.topk_prompt_logprobs     # Optional[list[Optional[list[tuple[int, float]]]]] — top-K

for seq in response.sequences:
    seq.tokens       # list[int] — generated token IDs
    seq.logprobs     # Optional[list[float]] — per-token logprobs
    seq.stop_reason  # StopReason: "length" | "stop"

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

# TrainingRun — metadata about a training run
run.training_run_id    # str
run.base_model         # str
run.is_lora            # bool
run.lora_rank          # Optional[int]
run.last_checkpoint    # Optional[Checkpoint]
run.user_metadata      # Optional[dict[str, str]]

# Checkpoint — metadata about a saved checkpoint
ckpt.checkpoint_id     # str
ckpt.checkpoint_type   # CheckpointType: "training" | "sampler"
ckpt.tinker_path       # str (tinker:// path)
ckpt.size_bytes        # Optional[int]
ckpt.public            # bool
ckpt.expires_at        # Optional[datetime]

# Parse a tinker:// path
parsed = ParsedCheckpointTinkerPath.from_tinker_path("tinker://run-id/weights/ckpt-id")
parsed.training_run_id  # str
parsed.checkpoint_type  # CheckpointType
parsed.checkpoint_id    # str

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

评价

还没有评价。欢迎分享你的使用感受。

评论

无需登录即可发表。欢迎分享使用感受、提问,或说明在哪些环境下无法运行。

还没有评论。来写第一条吧。

提交后会立即公开。请勿填写邮箱、电话等个人信息。URL 最多 2 个。

0 / 1000 字

此表单受 reCAPTCHA 保护,适用 Google 的隐私权政策和服务条款。

同一仓库的技能

Guide for checkpointing — saving, loading, and resuming training with CheckpointRecord. Use when the user asks about saving weights, resuming training, checkpoint management, or the checkpoint lifecycle.

中文简介正在准备中。当前显示原文说明。

uiuc-kang-lab/rlvr_generalization_bounds52026年5月13日 更新

ci

免费

Guide for testing conventions and CI pipelines — unit tests, integration smoke tests, pytest markers, and GitHub Actions workflows. Use when the user asks about testing, CI, running tests, or adding tests for a recipe.

中文简介正在准备中。当前显示原文说明。

uiuc-kang-lab/rlvr_generalization_bounds52026年5月13日 更新

Guide for using completers — TokenCompleter and MessageCompleter for text generation during RL rollouts and evaluation. Use when the user asks about generating text, completing messages, or using completers in RL environments.

中文简介正在准备中。当前显示原文说明。

uiuc-kang-lab/rlvr_generalization_bounds52026年5月13日 更新

Guide for contributing to the tinker-cookbook repo — development setup, code style, type checking, PR process, and design conventions. Use when the user asks about how to contribute, set up the dev environment, code style, or project conventions.

中文简介正在准备中。当前显示原文说明。

uiuc-kang-lab/rlvr_generalization_bounds52026年5月13日 更新

datasets

免费

Guide for dataset construction — SupervisedDatasetBuilder, RLDatasetBuilder, ChatDatasetBuilder, and custom dataset creation from JSONL, HuggingFace, or conversation data. Use when the user asks about datasets, data loading, data preparation, or custom data formats.

中文简介正在准备中。当前显示原文说明。

uiuc-kang-lab/rlvr_generalization_bounds52026年5月13日 更新

Set up and run knowledge distillation (on-policy, off-policy, or multi-teacher) from a teacher model to a student model using the Tinker API. Use when the user wants to distill knowledge, compress models, or train a student from a teacher.

中文简介正在准备中。当前显示原文说明。

uiuc-kang-lab/rlvr_generalization_bounds52026年5月13日 更新

查看 uiuc-kang-lab 的全部技能

报告此技能的问题