Repository navigation
Custom Dataset refactoring + docs - #715
Conversation
|
This is ready for a review @tianyu-l |
|
The failure in CI seems like a flake with glib 2.8? |
tianyu-l
left a comment
There was a problem hiding this comment.
This is very cool!
I had some inline suggestions. As part of the test, would you also please share a sceenshot of the C4 dataset working properly? In CI, only c4_test is tested.
| 1. Install TorchTitan from source: | ||
| ```bash | ||
| pip install -e . | ||
| ``` |
There was a problem hiding this comment.
nit: I don't think one needs to pip install to use torchtitan :)
There was a problem hiding this comment.
huh interesting this wasn't obvious to me
| # Force lowercase for consistent comparison | ||
| dataset_name = dataset_name.lower() | ||
|
|
||
| if dataset_name not in _supported_datasets: |
There was a problem hiding this comment.
the tutorial didn't mention that we need to update the _supported_datasets with new dataset and its path, so it would fail here. I'd recommend we always let user specify the triple, including a default path (but still with the dataset_path overriding option).
There was a problem hiding this comment.
I took your feedback and it was helpful to refactor the code and make it much simpler
|
Test logs [training]
batch_size = 1
seq_len = 8192
warmup_steps = 200 # lr scheduler warm up
max_norm = 1.0 # grad norm clipping
steps = 1000
data_parallel_replicate_degree = 1
data_parallel_shard_degree = -1
tensor_parallel_degree = 1
compile = false
dataset = "c4"rank0]:2024-12-05 13:24:36,127 - root - INFO - Starting job: Llama 3 8B training
[rank0]:2024-12-05 13:24:36,128 - root - INFO - Deterministic training off
[rank0]:2024-12-05 13:24:36,915 - root - WARNING - ENV[TORCH_NCCL_ASYNC_ERROR_HANDLING] = 1 will be overridden to 3 based on job config
[rank0]:2024-12-05 13:24:36,917 - root - INFO - CUDA capacity: NVIDIA H100with 95.00GiB memory
[rank0]:2024-12-05 13:24:36,995 - root - INFO - Peak FLOPS used for computing MFU: 9.890e+14
[rank0]:2024-12-05 13:24:36,995 - root - INFO - Building 1-D device mesh with ['dp'], [8]
[rank0]:2024-12-05 13:24:36,995 - root - INFO - Building tiktoken tokenizer locally from ./torchtitan/datasets/tokenizer/original/tokenizer.model
[rank0]:2024-12-05 13:24:37,139 - root - INFO - TikTokenizer built: #words 128256, BOS ID 128000, EOS ID 128001
[rank0]:2024-12-05 13:24:37,139 - root - INFO - Preparing c4 dataset from allenai/c4
[rank0]:2024-12-05 13:24:45,960 - root - INFO - Building llama3 8B with ModelArgs(dim=4096, n_layers=32, n_heads=32, n_kv_heads=8, vocab_size=128256, multiple_of=1024, ffn_dim_multiplier=1.3, norm_eps=1e-05, rope_theta=500000, max_seq_len=8192, depth_init=True, norm_type='rmsnorm')
[rank0]:2024-12-05 13:24:46,098 - root - INFO - Model llama3 8B size: 8,030,261,248 total parameters
[rank0]:2024-12-05 13:24:46,099 - root - INFO - Applied selective activation checkpointing to the model
[rank0]:2024-12-05 13:24:46,163 - root - INFO - Applied FSDP to the model
[rank0]:NCCL version 2.21.5+cuda12.4
[rank0]:/home/marksaroufim/.conda/envs/titan/lib/python3.10/site-packages/torch/nn/init.py:51: UserWarning: No PYTORCH_KERNEL_CACHE_PATH or HOME environment variable set! This disables kernel caching. (Triggered internally at ../aten/src/ATen/native/cuda/jit_utils.cpp:1426.)
[rank0]: tensor.erfinv_()
[rank0]:2024-12-05 13:24:54,885 - root - INFO - CUDA memory usage for model: 3.77GiB(3.97%)
[rank0]:2024-12-05 13:24:54,894 - root - INFO - Checkpointing active. Checkpoints will be loaded from and saved to ./outputs/checkpoint
[rank0]:2024-12-05 13:24:54,895 - root - INFO - Loading the checkpoint at step 200. |
tianyu-l
left a comment
There was a problem hiding this comment.
Looks really good. Thank you!
Please address the remaining comments before merging.
| enable_checkpoint = true | ||
| folder = "checkpoint" | ||
| interval_type = "steps" | ||
| interval = 500 | ||
| interval = 10 |
There was a problem hiding this comment.
Looks accidental changes, pls revert
| - `text_processor`: Function to process individual samples | ||
| - The loader function should return a HuggingFace dataset object | ||
| - The processor function should return a string that combines the relevant fields from your dataset | ||
| - Use streaming=True for large datasets to manage memory efficiently |
There was a problem hiding this comment.
nit:
| - Use streaming=True for large datasets to manage memory efficiently | |
| - Use `streaming=True` for large datasets to manage memory efficiently |
|
oh also, since you have a nice |
EDIT: removed the specific new functions in hf_datasets.py and kept most of the doc changes and will not go for a registration based API Fixes pytorch#311 This PR describes the status quo of how new datasets should be registered today, in that there's the implicit assumption that people are installing torchtitan from source and updating hf_datasets.py to support new datasets. As an example I passed in the wikipedia dataset The main "nice" thing about this PR is that `class HuggingFaceDataset` is now agnostic to the c4 dataset which makes it easier for new people to add datasets without reading the rest of the file There's another direction this PR could have went in which was to allow custom dataset registration, the benefit is people can support new datasets without installing titan from source but registration apis can feel kinda "bureaucratic" and presumably people would need to register the dataset somewhere, probably `train.py`? Not totally sure which is more in line with the repo's goals so opening this PR to discuss ```python def register_dataset( name: str, loader: Callable[[str, Dict[str, Any]], Any], processor: Callable[[Dict[str, Any]], str], path: Optional[str] = None, ) -> None: DATASET_LOADERS[name] = loader DATASET_TEXT_PROCESSORS[name] = processor def wikipedia_loader(dataset_path: str, **kwargs): return load_dataset( dataset_path, name="20220301.en", split="train", streaming=True, trust_remote_code=True, ) def wikipedia_processor(sample: Dict[str, Any]) -> str: return f"{sample['title']}\n\n{sample['text']}" register_dataset( name="wikipedia", loader=wikipedia_loader, processor=wikipedia_processor, path="wikipedia" ) ```
EDIT: removed the specific new functions in hf_datasets.py and kept most of the doc changes and will not go for a registration based API Fixes pytorch#311 This PR describes the status quo of how new datasets should be registered today, in that there's the implicit assumption that people are installing torchtitan from source and updating hf_datasets.py to support new datasets. As an example I passed in the wikipedia dataset The main "nice" thing about this PR is that `class HuggingFaceDataset` is now agnostic to the c4 dataset which makes it easier for new people to add datasets without reading the rest of the file There's another direction this PR could have went in which was to allow custom dataset registration, the benefit is people can support new datasets without installing titan from source but registration apis can feel kinda "bureaucratic" and presumably people would need to register the dataset somewhere, probably `train.py`? Not totally sure which is more in line with the repo's goals so opening this PR to discuss ```python def register_dataset( name: str, loader: Callable[[str, Dict[str, Any]], Any], processor: Callable[[Dict[str, Any]], str], path: Optional[str] = None, ) -> None: DATASET_LOADERS[name] = loader DATASET_TEXT_PROCESSORS[name] = processor def wikipedia_loader(dataset_path: str, **kwargs): return load_dataset( dataset_path, name="20220301.en", split="train", streaming=True, trust_remote_code=True, ) def wikipedia_processor(sample: Dict[str, Any]) -> str: return f"{sample['title']}\n\n{sample['text']}" register_dataset( name="wikipedia", loader=wikipedia_loader, processor=wikipedia_processor, path="wikipedia" ) ```
## Why The Qwen3.8-Flash-Next QSA attention (#5782) will use `gather_attn`'s grouped-KV / separate-V Triton kernels. They first appear in attention-gym v0.0.19, after attention-gym #678, #701, #702, #713, #714, #715 and #703. torchtitan pins `26beb363`, which predates all of these. This PR only bumps the pin; the Flash-Next change stays in #5782. ## What changed (all mechanical) | | Before | After | | --- | --- | --- | | attn-gym pin | `26beb363` (#704 merge) | `0d0197fb` (v0.0.19 tag, #703 merge) | - `.ci/docker/requirements.txt` (root `requirements.txt` symlinks to it): new SHA. The TODO now says to switch to the PyPI release once v0.0.19 is published there (PyPI's newest is 0.0.18). #704, which the old TODO waited on, is already included in both pins. - `torchtitan/models/common/attn_gym.py` (install hint) and `tests/unit_tests/cpu/models/common/test_optional_imports.py` (2 asserts): same SHA. ## Why v0.0.19 rather than attention-gym `main` `26beb363..0d0197fb` changes only `attn_gym/sparse/gather_attn` (plus its tests and docs). I diffed the two installed `attn_gym` trees to confirm this. GDN, KDA, short_conv, the indexer, MLA and the CuTe backend are byte-identical, so qwen3_5, qwen3_8, kimi and the deepseek_v4 indexer can't change. `main` would also pull in the warpdrive rewrite and the indexer/delta-H ports (~28 `_delta_rule` files). ## Numerics The only `gather_attn` consumer is `torchtitan/models/deepseek_v4/attention.py`. Old vs new pin, 10 steps, seed 42, deterministic, loss and grad_norm read from TensorBoard via `scripts/loss_compare.py`, on GB300: | Config | GPUs | Result | | --- | --- | --- | | `deepseek_v4_debugmodel_fsdp4_ep4` (DistMuon) | 4 | bitwise identical* | | `deepseek_v4_debugmodel_fsdp2_tp2_ep2_pp2` with dp_shard=1 (host has 4 GPUs) | 4 | bitwise identical* | \* With `gather_attn`'s Triton tuners pinned to the same candidate in both runs. Without pinning, deepseek_v4 isn't run-to-run reproducible on **either** pin when the autotune cache is cold. `_FWD_TMA` and `_BWD_DLOCAL_KV_TMA` choose `num_warps` 4 vs 8 by timing, and the two give different bits. Ranks and cold-cache runs can pick different winners, and torch's deterministic flag doesn't control this. This already happens on main. I filed it upstream as meta-pytorch/attention-gym#777, with a single-GPU repro. Because of it, this PR adds no deepseek_v4 golden; see follow-ups. ## Testing - `pre-commit run --all-files` passes, including `pyrefly-check`. - `pytest tests/unit_tests/cpu/models/common` plus the deepseek_v4, qwen3_5, qwen3_8 and kimi_k3 CPU tests: 416 passed. The same 9 tests fail with both the old and new pin on this aarch64 host (`test_lora_forward` and 8 qwen3_5 tests). The one I inspected, `test_lora_forward`, fails with "torch.compile on current platform is not supported for CPU". ## Known issues / follow-ups - deepseek_v4 golden numerics: add once attention-gym#777 lets us fix the tile config. The golden then has to be exported on CI's A10G runners, not on GB300.
EDIT: removed the specific new functions in hf_datasets.py and kept most of the doc changes and will not go for a registration based API
Fixes #311
This PR describes the status quo of how new datasets should be registered today, in that there's the implicit assumption that people are installing torchtitan from source and updating hf_datasets.py to support new datasets. As an example I passed in the wikipedia dataset
The main "nice" thing about this PR is that
class HuggingFaceDatasetis now agnostic to the c4 dataset which makes it easier for new people to add datasets without reading the rest of the fileThere's another direction this PR could have went in which was to allow custom dataset registration, the benefit is people can support new datasets without installing titan from source but registration apis can feel kinda "bureaucratic" and presumably people would need to register the dataset somewhere, probably
train.py?Not totally sure which is more in line with the repo's goals so opening this PR to discuss