Open
[Feature]: 数据集 Offline/Online 流程转测目标 #339
rongyueAdd on Aug 17
Aug 17 Modify description of issue
Aug 18 Modify description of issue
Aug 18 Modify description of issue
Aug 19 Modify description of issue
Aug 19 Modify description of issue
Aug 26 Change title to "[Feature]: 数据集 Offline/Online 流程转测目标", originally titled "数据集 Offline/Online 流程转测目标".
Aug 26 Change title to "[Feature]: 数据集 Offline/Online 流程转测目标", originally titled "数据集 Offline/Online 流程转测目标".
数据集 Offline/Online 流程转测目标
1. 转测背景与总体目标
本次转测用于验证 HyperParallel LLM 数据集在 Offline 和 Online 两类数据处理流程下的接口可用性、
配置有效性以及训练接入能力。
两类流程分别通过以下对外入口构建训练数据集:
from hyper_parallel.auto_models.components.datasets.llm import ( build_indexed_text_dataset, build_online_text_dataset, )build_indexed_text_dataset:进入离线 Indexed Dataset 读取流程。build_online_text_dataset:进入在线 Hugging Face Dataset 读取流程。data_config.dataset_type继续区分mapping和iterable。apply_llm_data_transform,输出训练所需的 ModelSample。plaintext或conversationtransform 动态完成 Tokenize。.bin/.idx数据。整体调用链如下:
本期总体转测目标如下:
plaintext主流程;conversation不纳入本期转测。mapping、iterable两类 Online Dataset。本期统一限制如下:
pack_to_seq_len的定长 packing 流程。text。2. Offline 数据集流程
2.1 功能范围
Offline 流程负责将 Hugging Face Dataset 或本地 JSON/JSONL 数据提前完成 Tokenize,生成
Megatron-compatible Indexed Dataset:
本期 Offline 转测范围如下:
.bin/.idx文件。text,CLI 统一使用--json-keys text。AutoTokenizer的UserWarning,该提示不代表处理失败。keep_sequential_samples。pack_to_seq_len生成长度为seq_len + 1的定长 document,并丢弃每个 partition 最后的不足一条的残余样本。本期 Offline 不测试:
2.2 Offline CLI 对外接口
Offline 数据制备提供两个 CLI 入口:
两个入口最终进入统一的 Offline 预处理流程,完成数据分区、Tokenize、可选定长 packing、partition 产物合并及
.bin/.idx文件生成。本期两个入口均验证默认不定长模式和pack_to_seq_len定长模式。2.3 Hugging Face 数据集 CLI
命令入口:
使用示例:
python -m hyper_parallel.auto_models.components.datasets.tools.huggingface_offline \ --dataset Salesforce/wikitext \ --dataset-subset wikitext-103-raw-v1 \ --dataset-split train \ --json-keys text \ --output-prefix ./offline_datasets/wikitext/train \ --tokenizer gpt2 \ --workers 8 \ --partitions 2 \ --keep-sequential-samples \ --append-eod true \ --pack-to-seq-len 4096处理流程:
2.3.1 Hugging Face CLI 参数
--dataset--dataset-subsetNone--dataset-splittrain--revisionNone--cache-dirNone--data-dirNone--data-filesNoneload_dataset()的源文件--num-procNone--json-keystexttext--output-prefix<prefix>_text_document.bin/.idx--download-dir--tokenizer--tokenizer-use-fastTrue--trust-remote-codeFalse--append-eodTruetrue或false--workers8--partitions1--keep-sequential-samplesFalse--pack-to-seq-lenNone--keep-partition-filesFalse.bin/.idx产物2.4 本地数据集 CLI
命令入口:
使用示例:
python -m hyper_parallel.auto_models.components.datasets.tools.offline_preparation \ --dataset-name-or-path ./dataset/train.jsonl \ --json-keys text \ --output-prefix ./offline_datasets/train \ --tokenizer-name-or-path gpt2 \ --workers 8 \ --partitions 2 \ --keep-sequential-samples \ --append-eod true \ --pack-to-seq-len 4096处理流程:
2.4.1 本地数据集 CLI 参数
--dataset-name-or-path--json-keystexttext--output-prefix<prefix>_text_document.bin/.idx--tokenizer-name-or-path--tokenizer-use-fastTrue--trust-remote-codeFalse--chat-templateNone--add-special-tokensNone--split-sentencesFalse--keep-newlinesFalse--langenglish--append-eodTruetrue或false--workers8--partitions1--keep-sequential-samplesFalse--pack-to-seq-lenNone--keep-partition-filesFalse.bin/.idx产物--log-interval10002.4.2 本地多文件输入
本地入口不使用
--data-files。多个输入文件通过目录或非递归 glob 指定。目录方式:
glob 方式:
python -m hyper_parallel.auto_models.components.datasets.tools.offline_preparation \ --dataset-name-or-path "./dataset/train-*.jsonl" \ --json-keys text \ --output-prefix ./offline_datasets/train \ --tokenizer-name-or-path gpt2转测要求:
.json、.jsonl、.json.gz和.jsonl.gz。**递归匹配。2.5 两个 Offline CLI 的接口差异
huggingface_offlineoffline_preparation--dataset--dataset-name-or-path--tokenizer--tokenizer-name-or-path--data-files--cache-dirkeep_sequential_samplespack_to_seq_len.bin/.idx.bin/.idx2.6 Offline 单文本输入格式
本期 Offline 仅转测以下格式:
{"text": "This is the first document."} {"text": "This is the second document."}统一配置:
转测要求:
text字段存在且为字符串时能够正常 Tokenize。text字段时明确报错。<output-prefix>_text_document.bin/.idx。多字段、嵌套对象、
messages、prompt/response、多模态及预先 Tokenize 的输入不纳入转测。2.7 多分片及顺序保持
Offline 多分片通过以下参数控制:
约束如下:
转测要求:
partitions=1和partitions>1。workers、partitions必须为正整数。ValueError。.bin/.idx。--keep-sequential-samples后,各 partition 获得连续记录区间。动态 Worker 数选择及相关参数
--find-optimal-num-workers、--workers-to-check、--max-documents不作为本期转测目标。2.8
pack_to_seq_len本期验证
pack_to_seq_len=None的默认不定长流程,以及显式配置序列长度后的定长 packing 流程。例如:
启用后,处理语义如下:
chunk_size = pack_to_seq_len + 1,例如配置4096时,每个输出 document 长度为4097。4097个 Token 写入 Indexed Dataset。4097的 Token buffer,则直接丢弃。pad_token_id或eos_token_id补齐写入。pack_to_seq_len<=0时返回ValueError。pack_to_seq_len且设置--append-eod false时仍可生成产物,但代码会输出UserWarning,提示原始文档边界不包含 EOD。转测要求:
pack_to_seq_len=None时按原始不定长 document 写入。pack_to_seq_len=4096时所有输出 document 长度均为4097。.bin/.idx产物能够被训练侧正常读取。3. Online 数据集流程
3.1 功能范围
Online 流程在训练期间读取原始数据,并动态完成格式转换和 Tokenize。本期范围如下:
mapping和iterable两种 Dataset 类型。text列。DynamicBatchDataLoader在 token budget 内动态选择 K 条样本并完成 Online packing。非 Hugging Face Tokenizer、自定义 Tokenizer、多文本字段、复杂字段映射、多模态输入和私有数据集鉴权不纳入转测。
3.2 Online 统一 YAML 接口
当前 Mapping + 动态 batching 端到端实验从仓库根目录运行:
验收要求为至少完成 3 个训练 step,进程退出码为 0,日志无
ERROR或Traceback,loss 不为NaN或Inf。dataset: _target_: hyper_parallel.auto_models.components.datasets.llm.build_online_text_dataset data_path: null data_config: dataset_type: mapping hf_dataset_name: Salesforce/wikitext hf_config_name: wikitext-2-raw-v1 cache_dir: ./dataset_cachedataset._target_strhyper_parallel.auto_models.components.datasets.llm.build_online_text_datasetdataset.data_pathstr/list/nullNonedata_config.dataset_typestrmappingmapping、iterabledata_config.hf_dataset_namestr/nullNonedata_config.hf_config_namestr/nullNonedata_config.cache_dirstr/nullNonedata_config.shuffleboolTruedata_config.shuffle_buffer_sizeint10000data_config.split_by_data_parallelboolTrue当
hf_dataset_name和data_path同时配置时,优先使用hf_dataset_name。当前 Online 数据固定读取trainsplit;Iterable Shuffle 使用training.seed。3.3 Plaintext 流程
输入格式:
{"text": "This is an online training sample."}dataset: model_assets: chat_template: null tokenizer: _target_: hyper_parallel.auto_models.components.datasets.llm.build_tokenizer.AutoTokenizer.from_pretrained pretrained_model_name_or_path: ./qwen3-model use_fast: true data_transform: _target_: hyper_parallel.auto_models.components.datasets.llm.build_data_transform.build_llm_data_transform data_type: plaintext text_keys: text max_seq_len: 2048 _target_: hyper_parallel.auto_models.components.datasets.llm.build_online_text_dataset data_path: null data_config: dataset_type: mapping hf_dataset_name: Salesforce/wikitext hf_config_name: wikitext-2-raw-v1 cache_dir: ./dataset_cache dataloader: _target_: hyper_parallel.auto_models.components.datasets.DynamicBatchDataLoader min_buffered_samples: 200 collate_fn: _target_: hyper_parallel.auto_models.components.datasets.build_online_text_collate_fn get_batch: _target_: hyper_parallel.auto_models.components.datasets.ParallelBatch source_type: online attention_mode: dense转测要求:
text_keys=text能够正确读取文本列。input_ids和相同内容的labels,causal label shift 由模型完成。max_seq_len。ParallelBatch构建训练字段。3.4 Conversation 流程
Online 代码支持
conversation数据格式及 ChatTemplate 转换,但本期不进行 Conversation 转测,包括:messages字段输入;loss_mask和 Label Mask;3.5 Mapping Dataset
Mapping 模式使用
load_dataset(streaming=False)。转测要求:
len(dataset)和dataset[index]。cache_dir生效。hf_config_name选择结果正确。3.6 Iterable Dataset
Iterable 模式使用
load_dataset(streaming=True),随后执行可选 Buffer Shuffle 和 DP 分片。转测要求:
shuffle=true时启用 Buffer Shuffle。shuffle_buffer_size<=0时返回ValueError。split_by_data_parallel=true时,各 DP Rank 获取对应数据分片。Iterable 模式不要求完整数据集预先下载到本地缓存,也不验证随机索引和
len()。4. YAML 接口一致性要求
4.1 Plaintext
dataset._target_=hyper_parallel.auto_models.components.datasets.llm.build_online_text_dataset。dataset.data_transform.data_type=plaintext。dataset.model_assets.chat_template=null。dataset.model_assets.tokenizer必须配置 Hugging Face Tokenizer。dataloader.collate_fn使用build_online_text_collate_fn。dataloader.get_batch.source_type=online。text字段。4.2 Conversation
Conversation 相关 YAML 配置一致性不纳入本期转测。
4.3 Offline Pretokenized
model_assets.datasets_type=pretokenized。data_transform.data_type=pretokenized。data_config.source_type=offline。data_path。input_ids执行文本 Tokenize。5. 非本期转测范围
messages、多轮对话、Role、Tool Calling、Label Mask、DataLoader 和训练接入。6. 转测验收标准
.bin/.idx。text。pack_to_seq_len=N时,每个输出 document 长度均为N+1,每个 partition 最后的不足一条的残余样本被丢弃。keep_sequential_samples=true时,最终数据顺序与原始记录顺序一致。build_indexed_text_dataset接入训练。text字段并使用 Hugging Face Tokenizer 动态编码。data_type、dataset_type、DataLoadersource_type和 Tokenizer 配置关系正确。