feat: add pre-tokenized dataset cache to accelerate dynamics training#26
Open
tashapais wants to merge 1 commit into
Open
feat: add pre-tokenized dataset cache to accelerate dynamics training#26tashapais wants to merge 1 commit into
tashapais wants to merge 1 commit into
Conversation
Adds scripts/preprocess_tokens.py: runs a trained VideoTokenizer over an
entire dataset and saves token indices as [N, P] int32 to HDF5.
Adds TokenizedVideoDataset: loads pre-tokenized HDF5 and returns [T, P]
index sequences, with the same (tokens, 0) interface as VideoHDF5Dataset.
In train_dynamics.py, if cached_tokens_path is set and exists, the dataloader
returns token indices directly, skipping the video tokenizer forward pass
each training step. This eliminates the tokenizer bottleneck for repeated
runs on the same dataset.
Use: python scripts/preprocess_tokens.py --video_tokenizer_path <ckpt> \
--dataset PONG --output_path data/pong_tokens.h5
Then: set cached_tokens_path in configs/dynamics.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
scripts/preprocess_tokens.py: one-time script that runs a trainedVideoTokenizerover a full dataset and saves token indices as[N, P] int32to HDF5. Stores metadata (latent_dim, num_bins, codebook_size) as HDF5 attrs.TokenizedVideoDatasettodatasets/datasets.py: loads the pre-tokenized HDF5 and returns[T, P]index sequences, matching the(tokens, 0)interface ofVideoHDF5Dataset.train_dynamics.py: whencached_tokens_pathis set in config and the file exists, the dataloader returns token indices directly. The video tokenizer forward pass is skipped each training step, eliminating the per-batch tokenization overhead.cached_tokens_path: Optional[str] = NonetoDynamicsConfig.Why it matters: dynamics training repeats the same tokenization pass every step. With a large dataset and a GPU-bound tokenizer, this can cut 30-50% off wall-clock training time.
Usage
Test plan
preprocess_tokens.pyon a small dataset and verify HDF5 is created with correct shape[N, P]cached_tokens_pathset and verify loss curve matches raw-frame trainingcached_tokens_path: null(default) falls back to the original frame-loading path