Type-check rfd3 FabricTrainer (bring it under the mypy gate)#337
Open
lyskov-ai wants to merge 1 commit into
Open
Type-check rfd3 FabricTrainer (bring it under the mypy gate)#337lyskov-ai wants to merge 1 commit into
lyskov-ai wants to merge 1 commit into
Conversation
Clear rfd3.trainer.fabric_trainer (99 errors) from the mypy ignore-errors ratchet. The errors were one dominant pattern: the dynamically-keyed `state` bag was inferred as `dict[Any, Any] | int | None`, so every state access and counter update errored. Mirror the already-landed foundry trainers/fabric precedent: a class-level `state: dict[str, Any]` + `_current_train_return: Any`, an annotated `default_state`, a documented type-ignore on the wider str|int precision API, a cast on setup_dataloaders + widening the loop params to DataLoader, `get_latest_checkpoint -> Path | None` with a cast at the call site, and the truthful `load_legacy_checkpoint -> None`. Behaviour-preserving, mypy-only (no clean CPU-test target for this cluster-coupled trainer glue). Ratchet 4 -> 3 modules remaining. Co-authored-by: lyskov-ai <277346777+lyskov-ai@users.noreply.github.com>
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.
rfd3'sFabricTrainer(models/rfd3/src/rfd3/trainer/fabric_trainer.py) was exempted from mypy type-checking; this brings it under the gate.Most of the errors stemmed from the trainer's
statedictionary having no type annotation: mypy inferred its values asdict | int | Nonefrom the defaults literal, so everystate["model"].…access and step/epoch counter update failed to type-check. The fixes mirror the equivalent, already-type-checkedFabricTrainerin the shared layer (src/foundry/trainers/fabric.py):state: dict[str, Any](a deliberately loose, dynamically-keyed bag) and_current_train_return: Any;type: ignoreon theprecisionargument — our publicstr | intAPI is wider than Fabric's accepted literal union;setup_dataloadersresults, and widenedtrain_loop/validation_loopparameters to plainDataLoader;get_latest_checkpointreturn type corrected toPath | None(with a cast at its single call site);load_legacy_checkpointreturn type corrected toNone— it updatesstatein place and never returned a value.Annotations, casts, and corrected return types only — no behaviour change.