TraceDataset
Load the recordings of synalinks.record_traces() as a dataset.
TraceDataset
Bases: Dataset
Streaming dataset over the recordings of synalinks.record_traces().
Reads the folders the synalinks.hooks.Recorder writes (one per program
and originating module) and yields one example per recorded LM call:
by default the input is the ChatMessages the LM received and the
target is the ChatMessage it answered. Use it to evaluate a program
on recorded traffic, to distill a large model into a smaller one, or
to inspect what was recorded.
Examples recorded in any Recorder format ("openai", "tinker",
"customizer") are read back as chat-completion messages: a <think>
prefix ("tinker") or a separate thinking message ("customizer")
becomes reasoning_content, and object tool-call arguments become JSON
strings. The tool-call ids the "customizer" format drops are
renumbered, and each tool result is linked back to its call in order.
import synalinks
dataset = synalinks.datasets.TraceDataset(
program="my_program",
module="generator",
deduplicate=True,
batch_size=8,
)
await program.evaluate(x=dataset)
Every example is also given to the templates with its recorded
metadata, so input_template / output_template can remap it onto a
program's own data models. The template variables are messages (the
input messages), completion (the assistant's answer), tools (the
tools the LM was given, [] if none) and the metadata.jsonl keys
(program, module, outputs, schema, usage, cost,
timestamp, session_id, call_id, parent_call_id, inputs_hash,
config_hash, format). For example, to train a module on the
structured answers it gave:
dataset = synalinks.datasets.TraceDataset(
module="generator",
output_data_model=Answer,
output_template="{{ outputs | tojson }}",
)
To give each example the tools its LM call had, pass
tools_template="{{ tools | tojson }}".
deduplicate and drop_prefixes read a whole module folder before
yielding its examples; otherwise the files are streamed line by line.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
root
|
str
|
The recording root. Defaults to the one of
|
None
|
program
|
str
|
Optional. Only read this program's recordings. |
None
|
module
|
str
|
Optional. Only read this module's recordings: its
name, or its name-scope path below the program
(e.g. |
None
|
include_unsupported
|
bool
|
Also read the complete conversations
the recording format could not express (kept in |
False
|
config_hash
|
str
|
Optional. Only read examples produced by this
|
None
|
session_id
|
str
|
Optional. Only read examples of this recording session. |
None
|
since
|
float
|
Optional. Only read examples recorded at or after this time (seconds since the epoch). |
None
|
until
|
float
|
Optional. Only read examples recorded before this time (seconds since the epoch). |
None
|
deduplicate
|
bool
|
Keep only the latest example of each set of
identical inputs (same |
False
|
drop_prefixes
|
bool
|
Drop the examples whose whole conversation
is the beginning of another one of the same module: the
earlier steps of an agent trajectory, each repeated in the
next. Defaults to |
False
|
input_data_model
|
DataModel
|
See |
None
|
input_schema
|
dict | str
|
See |
None
|
input_template
|
str
|
See |
None
|
output_data_model
|
DataModel
|
See |
None
|
output_schema
|
dict | str
|
See |
None
|
output_template
|
str
|
See |
None
|
tools_template
|
str
|
See |
None
|
batch_size
|
int
|
Examples per yielded batch. Defaults to |
1
|
limit
|
int
|
Optional. Caps how many examples are read. With a
limit set, |
None
|
repeat
|
int
|
See |
1
|
Source code in synalinks/src/datasets/trace_dataset.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 | |