Repository navigation
Datasets and Calibration
Full signatures and usage: Dataset streams.
load(paths, type="dataset") streams a list or tuple of local shards in order. Each pass reopens them. Keep the path order stable when reproducing a calibration sample.
| Shard | Row representation |
|---|---|
| JSONL or JSON | One object per nonblank line, or a top-level array of objects for .json. Nested messages, IDs and masks retain their structure. |
| UTF-8 text | One {"text": line} per line, including empty lines. |
| CSV | A dictionary of strings using distinct, nonempty headers. Field counts must match. |
| Parquet or Arrow IPC | Typed row values; see binary formats. |
Text formats accept outer gzip compression. Outer Zstandard compression requires Python 3.14+ with compression.zstd. Binary shards use their internal compression. Register a custom reader per call with hf_compat.load_dataset(..., readers={".extension": function}); the function receives a local path and yields row dictionaries.
from pathlib import Path
from datashoal import load
shards = sorted(Path("calibration/train").glob("*.jsonl.gz"))
train = load(shards, type="dataset")
calibration = train.sample(128, seed=42)For a loaded GPT-QModel model, pass these rows to model.quantize(CalibrationConfig(dataset=calibration, batch_size=1)) using CalibrationConfig from gptqmodel.quantization. Text rows can carry text, chat rows messages, and tokenized rows input_ids and an optional attention_mask. GPT-QModel owns padding and tensor creation. Choose representative training examples and keep evaluation data separate.
| Operation | Timing and result |
|---|---|
map(fn) |
Lazy stream of the callback's returned rows. Return every field you want to retain. |
filter(predicate) |
Lazy stream containing matching rows. |
take(n) |
List of up to the first n rows. Stops consuming the stream at that prefix. |
sample(n, seed=...) |
Uniform reservoir sample in shuffled order. Scans the stream for positive n and keeps O(n) rows. |
batches(size) |
Iterator of lists, including the final partial batch. Size must be positive. |
collect() |
Materializes all rows in order. Budget memory for the entire result. |
from datashoal import Dataset
rows = Dataset(lambda: ({"id": i} for i in range(6)))
even = rows.filter(lambda r: r["id"] % 2 == 0).map(lambda r: {"input_ids": [r["id"]]})
assert list(even.batches(2)) == [[{"input_ids": [0]}, {"input_ids": [2]}], [{"input_ids": [4]}]]For a custom Dataset(factory), the factory must return a fresh iterable for each pass. For indexed or column access use the in-memory compatibility dataset.
Uncompressed regular local text, CSV and JSON inputs also use segmented mappings. Compressed text streams through its decompressor. Use take(n) for an automatically closed prefix read, or call close() on a partially consumed cursor to release its resources promptly.
Get started
- Installation and quickstart
- Python API reference
- Native templates
- Native extension ABI
- Loading reference
Prepare calibration data
Manage artifacts
Operate and contribute