| """Hugging Face Datasets loader for the DataSys LLM serving trace.""" |
|
|
| from __future__ import annotations |
|
|
| import json |
| from pathlib import Path |
|
|
| import datasets |
|
|
|
|
| _DESCRIPTION = """\ |
| An anonymized LLM serving request trace for systems research on request |
| patterns, token accounting, latency, and token-bucket reuse. |
| """ |
|
|
| _HOMEPAGE = "" |
| _LICENSE = "other" |
|
|
|
|
| class DataSysTraceConfig(datasets.BuilderConfig): |
| """Builder config for one JSONL file in the trace package.""" |
|
|
| def __init__(self, *, filename: str, features: datasets.Features, **kwargs): |
| super().__init__(**kwargs) |
| self.filename = filename |
| self.features = features |
|
|
|
|
| _MODEL_PARAMETERS = { |
| "temperature": datasets.Value("float64"), |
| "max_tokens": datasets.Value("string"), |
| "top_p": datasets.Value("float64"), |
| "frequency_penalty": datasets.Value("float64"), |
| "presence_penalty": datasets.Value("float64"), |
| "seed": datasets.Value("int64"), |
| } |
|
|
| _TRACE_FEATURES = datasets.Features( |
| { |
| "id": datasets.Value("string"), |
| "status": datasets.Value("string"), |
| "created_at": datasets.Value("string"), |
| "finished_at": datasets.Value("string"), |
| "model": datasets.Value("string"), |
| "model_parameters": _MODEL_PARAMETERS, |
| "reported_token_input": datasets.Value("int64"), |
| "reported_token_output": datasets.Value("int64"), |
| } |
| ) |
|
|
| _QWEN_BUCKET_FEATURES = datasets.Features( |
| { |
| **_TRACE_FEATURES, |
| "token_count": datasets.Value("int64"), |
| "bucket_ids": datasets.Sequence(datasets.Value("int64")), |
| } |
| ) |
|
|
|
|
| def _coerce_record(record: dict, include_buckets: bool) -> dict: |
| """Fill optional nested keys so strict feature schemas stay stable.""" |
| model_parameters = record.get("model_parameters") or {} |
| record["model_parameters"] = { |
| "temperature": model_parameters.get("temperature"), |
| "max_tokens": ( |
| None |
| if model_parameters.get("max_tokens") is None |
| else str(model_parameters.get("max_tokens")) |
| ), |
| "top_p": model_parameters.get("top_p"), |
| "frequency_penalty": model_parameters.get("frequency_penalty"), |
| "presence_penalty": model_parameters.get("presence_penalty"), |
| "seed": model_parameters.get("seed"), |
| } |
| if include_buckets: |
| record["bucket_ids"] = record.get("bucket_ids") or [] |
| return record |
|
|
|
|
| class DataSysTrace(datasets.GeneratorBasedBuilder): |
| """DataSys trace dataset builder.""" |
|
|
| VERSION = datasets.Version("1.0.0") |
| DEFAULT_CONFIG_NAME = "trace" |
|
|
| BUILDER_CONFIGS = [ |
| DataSysTraceConfig( |
| name="trace", |
| version=VERSION, |
| description="Full request-level trace metadata.", |
| filename="trace.jsonl", |
| features=_TRACE_FEATURES, |
| ), |
| DataSysTraceConfig( |
| name="qwen3-32b-buckets", |
| version=VERSION, |
| description="Qwen/Qwen3-32B subset with token-bucket IDs.", |
| filename="qwen3-32b-buckets.jsonl", |
| features=_QWEN_BUCKET_FEATURES, |
| ), |
| ] |
|
|
| def _info(self) -> datasets.DatasetInfo: |
| return datasets.DatasetInfo( |
| description=_DESCRIPTION, |
| features=self.config.features, |
| homepage=_HOMEPAGE, |
| license=_LICENSE, |
| ) |
|
|
| def _split_generators(self, dl_manager: datasets.DownloadManager): |
| data_file = dl_manager.download_and_extract(self.config.filename) |
| return [ |
| datasets.SplitGenerator( |
| name=datasets.Split.TRAIN, |
| gen_kwargs={"filepath": data_file}, |
| ) |
| ] |
|
|
| def _generate_examples(self, filepath: str): |
| include_buckets = "bucket_ids" in self.config.features |
| with Path(filepath).open("r", encoding="utf-8") as handle: |
| for idx, line in enumerate(handle): |
| line = line.strip() |
| if not line: |
| continue |
| yield idx, _coerce_record(json.loads(line), include_buckets) |
|
|