Skip to main content

Testing and development

Development install​

cd /path/to/speedtronic
python3 -m venv .venv
. .venv/bin/activate
python -m pip install -e '.[dev]'

The development extra installs:

pytest>=7.4
ruff>=0.5
tomli>=2.0 on Python 3.10

Logging extras are separate.

Prescribed checks​

python -m pytest -q
python -m ruff check src tests examples
python -m ruff format --check src tests examples
python -m compileall src

Pytest uses the tests/ directory and -ra. Ruff targets Python 3.10 and a 100-character line length.

Test philosophy​

The suite is CPU-only and uses fake Hub behavior where possible. It avoids network credentials and real accelerator requirements.

The current repository defines the v1 suite plus the v2 optimizer, systems, and asynchronous distributed tests. The generated inventory is the authoritative count.

Test inventory​

tests/test_config.py​

TestVerifies
test_config_yaml_aliases_and_accumulationTop-level run aliases, accumulation derivation, compile mapping
test_config_round_tripRedacted save/load and equality
test_unknown_keys_and_invalid_batchUnknown root rejection and invalid batch divisibility
test_distributed_role_inferenceEnabled repo-bearing config defaults to master
test_secret_can_be_redacted_for_serializationExplicit serialization redaction and redacted file save

tests/test_model.py​

TestVerifies
test_reference_transformer_forward_and_lossLogit/loss shape and backward gradients
test_reference_transformer_weight_tying_and_checkpoint_hookShared weights and checkpoint flag propagation
test_config_dimensionsDefault FFN width

tests/test_precision_data.py​

TestVerifies
test_cpu_precision_defaults_to_fp32CPU auto FP32 and explicit CPU FP16 fallback
test_streaming_text_dataset_and_tuple_collateText block emission and tuple collation

tests/test_training.py​

TestVerifies
test_trainer_runs_with_accumulation_and_checkpointThree CPU steps, metric count, and checkpoint pointer
test_accumulation_scales_gradients_and_reports_mean_lossMathematical gradient accumulation and mean loss
test_runtime_builds_reference_modelRuntime composition and one reference-model step

tests/test_distributed.py​

TestVerifies
test_pseudo_gradient_direction_and_averageBaseline-current sign and equal averaging
test_nesterov_outer_optimizerFirst Nesterov update formula and state shape
test_delta_path_parserValid and invalid delta paths
test_tied_model_state_can_be_safetensors_serializedClone behavior for tied storage

tests/test_hub.py​

TestVerifies
test_hub_transport_round_tripFake global/delta upload-download and collaborator grant
test_master_skips_corrupt_delta_and_persists_processed_setCorrupt input is skipped and no state file is written

tests/test_v2_optimizers.py​

Covers v2 config aliases, Newton–Schulz edge cases, Muon+ normalization, role-aware routing, hybrid/AdamW construction, closure forwarding, cautious masking, sparse rejection, and a CPU runtime smoke build.

tests/test_v2_systems.py​

Covers shape profiles and warning suggestions, standard-library logger compatibility, causal label alignment, scheduler defaults, and CPU OOO fallback.

tests/test_v2_distributed.py​

Covers asynchronous global polling, non-blocking delta dispatch, queue overflow, prepared resume, synchronous transport, and baseline retention on failure.

tests/test_v2_release.py​

Covers version synchronization, CLI redaction, and serialization of all v2 configuration sections.

Coverage matrix​

AreaDirect coverageImportant gaps
Config basicsGood scalar/alias/redaction coverageRare nested types and hardware/model compatibility
Trainer accumulationGood CPU scalar/list coverageResume equivalence, output-contract breadth
Reference modelBasic forward/lossRoPE, GQA, masks, causality, eval mode
CPU precisionPartialCUDA, MPS, fused, scaler resume
DataBasic plus worker shardingPrefetch, custom tokenizer, loader builder
CheckpointsBasic existence and final-step saveContents, retention, corruption, RNG
Hub transportFake happy pathRetries, real SDK variants, cache fallback
Outer optimizerBasic formula and publish-path testsComplex values and full recovery matrix
Outer loopCorrupt skip and lock-scope testsReal Hub aggregation and crash recovery
CoordinatorAsync dispatch, poll, resume, stop coverageMaster/worker real Hub lifecycle
CLIValidation redaction and exit codeParsing, overrides, train error mapping
Logging/hooksNoneCadence, JSONL, W&B, TensorBoard
Compile/checkpoint fallbackNoneTrainer fallback behavior
Packaging/docsVersion, wheel, Twine, docs build gatesPlatform matrix and CUDA runners

v2 verification​

The v2 tests cover:

  • scalar and mapping optimizer configuration;
  • Muon routing, tied weights, Newton–Schulz, Muon+, and cautious wrapping;
  • sparse/non-matrix rejection;
  • CPU shape profiles and warning suggestions;
  • causal label alignment and scheduler synchronization;
  • CPU no-op OOO behavior;
  • asynchronous delta dispatch, queue overflow, failure, and baseline retention;
  • synchronous transport compatibility.

CUDA stream parity, fused AdamW, and hardware-specific speedups require a CUDA runner and are not implied by the CPU suite.

Documentation coverage build​

The Docusaurus project has a separate coverage gate:

cd docs-site
npm ci
npm run build

Before compilation it:

  1. parses every local source module with Python's AST;
  2. generates one inventory page for all modules, classes, functions, methods, tests, configs, and examples;
  3. validates inventory paths and symbol anchors;
  4. validates sidebar coverage.

Docusaurus then fails on broken internal links and MDX issues.

Adding a source module​

When adding a Python module under src/speedtronic:

  1. Curate its conceptual responsibility in an appropriate page.
  2. Ensure the generated inventory includes all declarations.
  3. Add or update tests.
  4. Add a link from the module coverage page if needed.
  5. Run all Python and docs checks.

The generator requires no manual inventory edits; it rewrites the generated page.

Code style​

The repository uses:

  • Ruff E, F, and I rules;
  • 100-character lines;
  • from __future__ import annotations;
  • dataclasses for configuration and results;
  • explicit fallback logging for optional capabilities.

Test-data safety​

Do not add real credentials to configs or tests. The fake Hub API stores bytes in memory and does not use network access.

Related: Test Map, Generated Source Inventory, and Troubleshooting.