test: add pytest suite + CI; fix empty-shard crash in JsonLineDataset#10
Open
ajinkyajawale14499 wants to merge 1 commit into
Open
test: add pytest suite + CI; fix empty-shard crash in JsonLineDataset#10ajinkyajawale14499 wants to merge 1 commit into
ajinkyajawale14499 wants to merge 1 commit into
Conversation
Add a CPU-only pytest suite for the core pure-Python utilities and wire up
GitHub Actions CI:
- tests/test_config.py: ConfigNode, (to|from)-config-node converters, jsonable,
CustomJSONEncoder, and the --opts override parser (incl. KeyError/TypeError
paths) and load_config.
- tests/test_jsonl_dataset.py: mmap line indexing (trailing/no-trailing newline),
per-record decoding, multi-file global indexing, bounds checks, and the
on-disk line-start cache.
- tests/test_sampling.py: greedy/softmax logits_to_probs, sample_tokens,
gather_token_probs, and sample_residual (incl. matched-distribution fallback).
- .github/workflows/ci.yml: runs pytest on Python 3.10/3.12 with CPU-only torch.
While adding the dataset tests, found and fixed a crash: JsonLineDataset raised
ValueError ('cannot mmap an empty file') when a shard was 0 bytes. Empty shards
are now treated as 0 records.
rajpratham1
approved these changes
Jun 30, 2026
rajpratham1
left a comment
There was a problem hiding this comment.
Great addition! The new pytest suite significantly improves confidence in the core utilities, and the regression test for the empty JSONL shard fixes a real edge case that could otherwise crash dataset initialization. The CI workflow is lightweight and appropriate for CPU-only validation. Nice work improving both reliability and maintainability.
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.
What
Adds the repository's first automated test suite and CI, plus a small fix that the tests surfaced.
Tests (CPU-only, no GPU/model required)
tests/test_config.py—ConfigNodeattribute access, the recursiveto_config_node/config_to_plain_dictconverters,jsonable,CustomJSONEncoder(function/type/torch.dtype/Path/Namespace/ConfigNode), the--optsoverride parser (including theKeyError/TypeErrorpaths), andload_config.tests/test_jsonl_dataset.py—JsonLineDatasetmmap line indexing: length with and without a trailing newline, per-record decoding, multi-file global indexing, out-of-range bounds, and the on-disk line-start cache (write + reuse).CACHE_DIRis redirected to a temp dir so tests are hermetic.tests/test_sampling.py— deterministic surfaces of the sampling helpers: greedy/temperature-0 and softmaxlogits_to_probs,sample_tokens,gather_token_probs,sample_from_probs, andsample_residual(including the matched-distribution fallback).CI
.github/workflows/ci.ymlrunspyteston Python 3.10 and 3.12 with CPU-only torch, so it stays fast and needs no CUDA/triton. A rootconftest.pykeeps the project importable without an editable install.Fix
JsonLineDatasetwas found to crash when a shard is 0 bytes:ValueError: cannot mmap an empty file. Empty shards are now treated as 0 records (with a matching regression test, including an empty shard alongside populated files).Verification
All 42 tests pass locally (
python -m pytest tests). Happy to adjust scope, naming, or the Python matrix to match your preferences.