Utilities¶
BatchInfo
¶
Source code in tokensmith/utils.py
doc_idx
instance-attribute
¶
sample_idx
instance-attribute
¶
shuffle_idx
instance-attribute
¶
get_example_details_by_id
¶
Source code in tokensmith/utils.py
WriteableMMapIndexedDataset
¶
WriteableMMapIndexedDataset(dataset_prefix, batch_info_save_prefix, train_seq_len, train_iters, train_batch_size, seed, splits_string, packing_impl, allow_chopped, add_extra_token_to_seq)
Source code in tokensmith/utils.py
close
¶
simulate_training_run
¶
simulate_training_run(batch_info_prefix, train_seq_len, train_iters, train_batch_size, seed, splits_string, packing_impl, allow_chopped)
Simulates a training run by creating doc_idx, sample_idx, and shuffle_idx files for the training sets. This is a placeholder method. It is better to use files generated by the training run.
Source code in tokensmith/utils.py
get_corpus_document_by_id
¶
get_corpus_document_by_id(doc_index)
Reads a document from the MMapIndexedDataset by its index.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
int
|
The index of the document to read. |
required |
Returns:
Type | Description |
---|---|
ndarray
|
np.ndarray: A numpy array containing the data read from the document. |
Source code in tokensmith/utils.py
get_train_document_by_id
¶
get_train_document_by_id(doc_index)
Reads a document from the MMapIndexedDataset by its index.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
int
|
The index of the document to read. |
required |
Returns:
Type | Description |
---|---|
ndarray
|
np.ndarray: A numpy array containing the data read from the document. |
Source code in tokensmith/utils.py
get_example_by_id
¶
get_example_by_id(example_loc, return_doc_details=False)
Reads an example from the MMapIndexedDataset by its location in a training run.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
int
|
The index of the example to read. |
required |
|
bool
|
If True, returns the document details along with the data. |
False
|
Returns:
Name | Type | Description |
---|---|---|
list of np.ndarray: A list of numpy arrays, each containing the data read from the corresponding document segment. |
||
doc_details |
(dict, optional)
|
If |
Notes:
- If the sequence is contained within a single document, only one array is returned in the list.
- If the sequence spans multiple documents, the list contains one array per document segment.
- The dtype used for reading is inferred from corpus_index_.dtype
.
Source code in tokensmith/utils.py
write_example_into_corpus
¶
write_example_into_corpus(injection_loc, injection_data, dry_run=False)
Writes an example into the corpus at the specified location (sample number in a training run).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
int
|
The index of the example to write. |
required |
|
ndarray
|
The data to write into the corpus. |
required |
|
bool
|
If True, only simulates the write operation without actually modifying the corpus. |
False
|
Returns:
Name | Type | Description |
---|---|---|
doc_details |
dict
|
A dictionary containing details about the corpus documents where the data was injected. |
Source code in tokensmith/utils.py
inject_example_into_corpus
¶
inject_example_into_corpus(injection_loc, injection_data, injection_type, rng, dry_run=False)
Injects an example into the corpus at the specified location (sample number in a training run).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
int
|
The index of the example to inject. |
required |
|
ndarray
|
The data to inject into the corpus. |
required |
|
str
|
The type of injection, e.g., "seq_start" or "seq_shuffle". |
required |
|
Generator
|
Random number generator for sampling positions. |
required |
|
bool
|
If True, only simulates the injection operation without actually modifying the corpus. |
False
|
Source code in tokensmith/utils.py
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 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 |
|
warn_once
cached
¶
generate_training_sample
¶
perturb_dataset
¶
perturb_dataset(raw_dataset, batch_info, perturbation_dir, max_train_samples, max_train_batches, train_seq_len, add_extra_token_to_seq, injection_type, loc_sampler, seed, dry_run=False, perturbation_include_filters=None)
Source code in tokensmith/utils.py
392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 |
|