Motivation.
The training subsystem relies on two lightweight utility modules for data preparation and augmentation: src/speculators/train/noise_transforms.py and src/speculators/train/vocab_mapping.py. Both have incomplete test coverage and typing/docstring discrepancies:
-
noise_transforms.py:
- Defines
TransformTensors, AddGaussianNoise, and AddUniformNoise used for hidden state augmentation.
- It is a 26-line file that currently lacks docstrings, full type annotations on
__init__ and __call__, and does not define __all__.
- There are zero unit tests in the entire test suite covering this module.
-
vocab_mapping.py:
save_token_frequency_distribution() docstring states:
Returns:
Path to the saved frequency distribution file
However, the function returns None (either early returning return or terminating without returning path).
__all__ only lists 2 of the 4 functions defined in the module, omitting combine_token_frequency_distributions and get_target_vocab_size.
- In
combine_token_frequency_distributions, combined_token_freq is typed as Counter[str] = Counter(), even though token IDs are integers (Counter[int]).
- While
test_vocab_mapping_cli.py tests CLI argument parsing and caching, there are no direct unit tests validating build_vocab_mappings_from_distribution() (verifying offset tensor math, frequency sorting, and fallback padding) or combine_token_frequency_distributions().
Consolidating these into one issue provides a well-rounded contribution to the training pipeline utilities that runs entirely on CPU.
Proposed Change.
Part 1: src/speculators/train/noise_transforms.py
Part 2: src/speculators/train/vocab_mapping.py
Any Other Things.
- Verification Commands:
uv run pytest tests/unit/train/test_noise_transforms.py tests/unit/train/test_vocab_mapping.py
Motivation.
The training subsystem relies on two lightweight utility modules for data preparation and augmentation:
src/speculators/train/noise_transforms.pyandsrc/speculators/train/vocab_mapping.py. Both have incomplete test coverage and typing/docstring discrepancies:noise_transforms.py:TransformTensors,AddGaussianNoise, andAddUniformNoiseused for hidden state augmentation.__init__and__call__, and does not define__all__.vocab_mapping.py:save_token_frequency_distribution()docstring states:None(either early returningreturnor terminating without returningpath).__all__only lists 2 of the 4 functions defined in the module, omittingcombine_token_frequency_distributionsandget_target_vocab_size.combine_token_frequency_distributions,combined_token_freqis typed asCounter[str] = Counter(), even though token IDs are integers (Counter[int]).test_vocab_mapping_cli.pytests CLI argument parsing and caching, there are no direct unit tests validatingbuild_vocab_mappings_from_distribution()(verifying offset tensor math, frequency sorting, and fallback padding) orcombine_token_frequency_distributions().Consolidating these into one issue provides a well-rounded contribution to the training pipeline utilities that runs entirely on CPU.
Proposed Change.
Part 1:
src/speculators/train/noise_transforms.py__all__ = ["TransformTensors", "AddGaussianNoise", "AddUniformNoise"].__init__and__call__.tests/unit/train/test_noise_transforms.pywith tests:TransformTensors.transform()raisesNotImplementedError.AddGaussianNoisemutates specified tensor keys and leaves non-specified keys unmodified; preserves shape, dtype, and device; identity check whenstd=0.0.AddUniformNoisegenerates noise strictly bounded in[-std, std]; identity check whenstd=0.0.Part 2:
src/speculators/train/vocab_mapping.pysave_token_frequency_distribution()return behavior and docstring (either returnpathor update docstring toReturns: None).__all__.combine_token_frequency_distributions(Counter[int]).get_target_vocab_size.tests/unit/train/test_vocab_mapping.pywith tests:build_vocab_mappings_from_distribution: verifies ranking by frequency, padding behavior when unique tokens <draft_vocab_size, and confirmsdraft_idx + draft_to_target[draft_idx]maps correctly to target token IDs.combine_token_frequency_distributions: verifies merging multiple frequency dictionaries saved on disk.Any Other Things.
uv run pytest tests/unit/train/test_noise_transforms.py tests/unit/train/test_vocab_mapping.py