claude-opus-4.8-pi-traces
收藏资源简介:
***More expensive than anticpated so you only get 4 lol :P*** This dataset was generated using [teich](https://github.com/TeichAI/teich) by [TeichAI](https://huggingface.co/TeichAI) <img src="https://cdn-avatars.huggingface.co/v1/production/uploads/6837935ac3b7ffe0d2559ce9/-AxyvV4wfUY8uo87kNKkK.png" width="20" height="20" style="display: inline-block; vertical-align: middle; margin: 0 3px;"> Prepare these datasets for supervised fine-tuning in just a few lines of code — see the **Conversion** section below. # Claude Opus 4.8 Pi Traces This directory contains raw agent trace files generated by teich. All assistant responses were generated by **anthropic/claude-opus-4.8**. JSONL files: 4 ## Training-ready tools A complete configured `tools` schema snapshot is embedded in the collapsed section at the bottom of this README. Use it when rendering loaded examples through your training chat template. `load_traces` applies this snapshot to each loaded example as the `tools` field. ## Format Each file is newline-delimited JSON representing a single captured agent session. The trace schema is designed for upload-first preservation so you can keep the original session history and convert it later for training. Teich normalizes split assistant fragments during trace copy and conversion so the semantic order is reasoning first, optional assistant text second, and tool calls last. Common top-level event groups: - `session_meta` - `turn_context` - `event_msg` - `response_item` - `session` - `message` - `session_info` - `model_change` - `thinking_level_change` - `external_session_meta` - `external_message` - `external_stderr` ## Example ```json {"type":"session","version":3,"id":"019e9f68-3075-7136-b429-c6b2c871ed67","timestamp":"2026-06-07T00:07:46.038Z","cwd":"/workspace"} {"type":"model_change","id":"9c4d2d98","parentId":null,"timestamp":"2026-06-07T00:07:46.097Z","provider":"openrouter","modelId":"anthropic/claude-opus-4.8"} {"type":"thinking_level_change","id":"9ae6b048","parentId":"9c4d2d98","timestamp":"2026-06-07T00:07:46.097Z","thinkingLevel":"high"} ``` ## Conversion ### Recommended: train with Unsloth and TRL `SFTTrainer` Use the trainer-first path: `prepare_data` renders trainer-friendly `text` rows with Teich supervision metadata, `SFTTrainer` tokenizes them, then `mask_data` applies Teich's multi-turn/tool-aware response-only labels: `oversized_policy='trim_followups'` lets multi-turn rows drop final follow-ups before oversized rows are discarded. ```python import os from unsloth import FastLanguageModel from trl import SFTConfig, SFTTrainer from teich import mask_data, prepare_data MAX_SEQ_LEN = 32768 MODEL_NAME = 'unsloth/Qwen3.5-0.8B' CHAT_TEMPLATE_KWARGS = {'enable_thinking': True} PUSH_TO_HUB_REPO_ID = 'username/teich-sft-model' HF_TOKEN = os.environ.get('HF_TOKEN') or '' model, tokenizer = FastLanguageModel.from_pretrained( model_name=MODEL_NAME, max_seq_length=MAX_SEQ_LEN, load_in_4bit=False, load_in_8bit=False, full_finetuning=False, ) model = FastLanguageModel.get_peft_model( model, r=32, target_modules=['q_proj', 'k_proj', 'v_proj', 'o_proj', 'gate_proj', 'up_proj', 'down_proj', 'out_proj'], lora_alpha=64, lora_dropout=0, bias='none', use_gradient_checkpointing='unsloth', random_state=3407, use_rslora=False, loftq_config=None, ) train_dataset = prepare_data( 'armand0e/claude-opus-4.8-pi-traces', tokenizer, split='train', max_examples=500, chat_template_kwargs=CHAT_TEMPLATE_KWARGS, max_length=MAX_SEQ_LEN, oversized_policy='trim_followups', tokenize=True, strict=True, ) trainer = SFTTrainer( model=model, tokenizer=tokenizer, train_dataset=train_dataset, eval_dataset=None, args=SFTConfig( dataset_text_field='text', dataset_num_proc=1, max_length=MAX_SEQ_LEN, packing=False, per_device_train_batch_size=1, gradient_accumulation_steps=4, warmup_steps=5, num_train_epochs=1, learning_rate=2e-4, logging_steps=1, optim='muon', optim_target_modules='all-linear', weight_decay=0.001, lr_scheduler_type='linear', output_dir='outputs', seed=3407, report_to='none', ), ) trainer = mask_data( trainer, tokenizer=tokenizer, train_on_reasoning=True, train_on_final_answers=True, train_on_tools=True, ) trainer_stats = trainer.train(resume_from_checkpoint=False) model.push_to_hub_merged(PUSH_TO_HUB_REPO_ID, tokenizer, save_method='merged_16bit', token=HF_TOKEN) ``` `mask_data` keeps the normal trainer configuration flow while applying Teich's assistant/tool-call labels after trainer tokenization. Keep `packing=False` for this flow. If you want standard next-token training without Teich response-only labels, call `prepare_data(..., teich_masking=False)` and skip `mask_data()`. For preparation audits, call `prepare_data(..., return_report=True)` to receive a `PrepareReport` with dropped rows, oversized rows, trimmed rows, max token lengths, and row ids. Use `preserve_columns=True` or `preserve_columns=['metadata', 'raw_index', 'source_key']` when you want those fields kept in the prepared dataset. `validate_tools=True` checks assistant tool-call names and required arguments against each row's declared tools before rendering. You can combine this dataset with other Teich chat-only or tool-call datasets by passing a list of dataset IDs, local paths, or loaded `datasets.Dataset` objects: ```python train_dataset = prepare_data( ['armand0e/claude-opus-4.8-pi-traces', 'username/other-teich-dataset'], tokenizer, max_length=MAX_SEQ_LEN, oversized_policy='trim_followups', tokenize=True, chat_template_kwargs=CHAT_TEMPLATE_KWARGS, ) ``` For weighted mixes, pass a source mapping with `percentage`, `weight`, or per-source `max_examples`. Explicit ratios stay true: if a source cannot fill its share after filtering, Teich scales the total row count down instead of backfilling from another source. Global `chat_template_kwargs` are the default; source-level `chat_template_kwargs` override those keys for that dataset only. ```python train_dataset = prepare_data( { 'max_examples': 2_000, 'agent': {'source': 'armand0e/claude-opus-4.8-pi-traces', 'percentage': 80}, 'chat': { 'source': 'username/other-teich-dataset', 'percentage': 20, 'chat_template_kwargs': {'enable_thinking': False, 'preserve_thinking': False}, }, }, tokenizer, max_length=MAX_SEQ_LEN, oversized_policy='trim_followups', tokenize=True, chat_template_kwargs=CHAT_TEMPLATE_KWARGS, ) ``` ### Fallback: render loaded examples with your tokenizer Use `load_traces` directly only when you want to own the remaining training pipeline yourself: chat-template rendering, filtering, tokenization, label masking, packing policy, and auditing. `load_traces` returns rows with normalized `messages` ready for `tokenizer.apply_chat_template(...)`: ```python from teich import load_traces, row_fits_context, validate_tool_calls dataset = load_traces('armand0e/claude-opus-4.8-pi-traces') example = dataset[0] # load_traces drops rows ending on tool results by default; pass # drop_incomplete_traces=False only to inspect or repair incomplete rows. validate_tool_calls(example).raise_for_errors() assert row_fits_context(example, tokenizer, 32768, {'enable_thinking': True}) rendered = tokenizer.apply_chat_template( example['messages'], tools=example.get('tools') or [], tokenize=False, add_generation_prompt=False, enable_thinking=True, ) tokenized = tokenizer(rendered, truncation=True, max_length=32768) ``` ## Tool schema snapshot <details> <summary>Training-ready tool schema snapshot</summary> ```json [ { "type": "function", "function": { "name": "bash", "description": "Run shell commands in the workspace.", "parameters": { "type": "object", "properties": { "command": { "type": "string" }, "cmd": { "type": "string" }, "cwd": { "type": "string" }, "description": { "type": "string" }, "timeout": { "type": "integer" } }, "anyOf": [ { "required": [ "command" ] }, { "required": [ "cmd" ] } ], "additionalProperties": true } } }, { "type": "function", "function": { "name": "edit", "description": "Edit file contents in the workspace.", "parameters": { "type": "object", "properties": { "path": { "type": "string" }, "file_path": { "type": "string" }, "edits": { "type": "array" } }, "required": [ "edits" ], "anyOf": [ { "required": [ "path" ] }, { "required": [ "file_path" ] } ], "additionalProperties": true } } }, { "type": "function", "function": { "name": "read", "description": "Read file contents from the workspace.", "parameters": { "type": "object", "properties": { "path": { "type": "string" }, "file_path": { "type": "string" }, "offset": { "type": "integer" }, "limit": { "type": "integer" } }, "anyOf": [ { "required": [ "path" ] }, { "required": [ "file_path" ] } ], "additionalProperties": true } } }, { "type": "function", "function": { "name": "read_file", "description": "Read file contents from the workspace.", "parameters": { "type": "object", "properties": { "path": { "type": "string" } }, "required": [ "path" ], "additionalProperties": true } } }, { "type": "function", "function": { "name": "write", "description": "Write file contents in the workspace.", "parameters": { "type": "object", "properties": { "path": { "type": "string" }, "file_path": { "type": "string" }, "content": { "type": "string" } }, "required": [ "content" ], "anyOf": [ { "required": [ "path" ] }, { "required": [ "file_path" ] } ], "additionalProperties": true } } }, { "type": "function", "function": { "name": "write_file", "description": "Write file contents in the workspace.", "parameters": { "type": "object", "properties": { "path": { "type": "string" }, "content": { "type": "string" } }, "required": [ "path", "content" ], "additionalProperties": true } } } ] ``` </details>



