-
Notifications
You must be signed in to change notification settings - Fork 7
Complete Pyright Migration and Remove Mypy Parity Configuration #23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
- Add `requirements/utils/prune_torch_deps.py`:
- Implements iterative, transitive pruning of packages that are only required by `torch` (e.g., `networkx`, `sympy`, `mpmath`).
- Provides a CLI: `python prune_torch_deps.py <lockfile_path>`.
- Parses uv lockfile `# via` comments and prunes exclusive transitive deps using safe iterations.
- Simplify `requirements/utils/lock_ci_requirements.sh`:
- Remove complex awk-based pruning logic and replace it with a simple call:
`python "${SCRIPT_DIR}/prune_torch_deps.py" "${lockfile}"`.
- Keep nightly lockfile generation behavior and the two-step manual install workflow.
- Use `--index` (replaces deprecated `--extra-index-url`) for PyTorch nightly resolution.
- Security & maintenance:
- Document security rationale: restrict the dependency confusion attack surface by pruning torch-only packages while using `--index-strategy unsafe-best-match` during lockfile generation only.
- Keep installation workflow secure: manual two-step install or explicit nightly index for runtime.
- Tests & checks:
- All unit tests pass (164 passed, 52 skipped).
- Pre-commit hooks pass.
- Module placed in `requirements/utils/` — not included in `src/` coverage.
Files changed:
- Added: `requirements/utils/prune_torch_deps.py`
- Updated: `requirements/utils/lock_ci_requirements.sh`
- Updated: `requirements/ci/requirements.txt` and `requirements/ci/requirements-oldest.txt` (torch-only deps pruned)
Notes:
- This refactor improves maintainability and makes pruning logic easier to test and extend.
- No change to the user-install workflow; nightly torch is still installed separately as before.
…set pyright mode to standard and remove initial warnings
|
@copilot ✅ Continue reducing the overall type checking error count, applying pattern fixes we've identified in the description and previous commits along with idiomatic patterns |
|
@speediedan I've opened a new pull request, #24, to work on those changes. Once the pull request is ready, I'll request review from you. |
* Initial plan * Remove mypy configuration and update pyright comments Co-authored-by: speediedan <[email protected]> * Enable reportAssignmentType check and fix variable shadowing in _reduce_transition Co-authored-by: speediedan <[email protected]> * Enable reportCallIssue check and fix LR scheduler instantiation Co-authored-by: speediedan <[email protected]> * Enable reportIndexIssue check and fix sharded optimizer indexing Co-authored-by: speediedan <[email protected]> * Enable reportGeneralTypeIssues and reorganize pyright config comments Co-authored-by: speediedan <[email protected]> * Fix spelling: Recieved -> Received in error messages Co-authored-by: speediedan <[email protected]> --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: speediedan <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR successfully completes the migration from mypy to pyright for type checking in the finetuning-scheduler repository. The migration upgrades pyright from "basic" to "standard" mode and removes all mypy-specific configuration. The PR achieves 0 type checking errors/warnings by applying targeted type annotation fixes and establishes reusable patterns for future type checking work.
Key changes include:
- Upgraded pyright to standard mode with comprehensive type checking enabled
- Fixed type inference issues through explicit type annotations, context manager casting, and variable scope adjustments
- Added security-focused dependency pruning utility to minimize attack surface when using PyTorch nightly
- Corrected multiple spelling errors in error messages ("Recieved" → "Received")
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
pyproject.toml |
Upgraded pyright to standard mode, removed mypy configuration, enabled comprehensive type checking rules |
src/finetuning_scheduler/strategy_adapters/base.py |
Updated _module_specific_freezing parameter type to accept both single Module and Iterable of Modules |
src/finetuning_scheduler/strategy_adapters/fsdp.py |
Added TYPE_CHECKING conditional import pattern and AbstractContextManager casting for context managers |
src/finetuning_scheduler/strategy_adapters/_wrap_utils.py |
Applied TYPE_CHECKING conditional import pattern for consistency with fsdp.py |
src/finetuning_scheduler/fts_supporters.py |
Fixed variable scope issues, corrected spelling errors, added type ignore directives for unavoidable inference limitations |
src/finetuning_scheduler/fts.py |
Renamed variables for type clarity to avoid shadowing |
requirements/utils/prune_torch_deps.py |
New utility script to prune torch-only dependencies from lockfiles to reduce dependency confusion attack surface |
requirements/utils/lock_ci_requirements.sh |
Integrated torch dependency pruning, updated security documentation, changed --extra-index-url to --index |
requirements/ci/requirements.txt |
Removed torch-only dependencies (mpmath, networkx, sympy), updated fastapi and protobuf versions |
requirements/ci/requirements-oldest.txt |
Updated fastapi and protobuf versions to match main requirements |
.github/workflows/copilot-setup-steps.yml |
New CI workflow for testing copilot environment setup with pyright validation |
Overview
This PR completes the migration from mypy to pyright for type checking in finetuning-scheduler. Building on the foundation established in previous work, this PR:
standardmode - Previously inbasicmode, now using comprehensive type checking[tool.mypy]section and mypy-parity directives frompyproject.tomlChanges Summary
Type Checking Fixes
Fixed Variable Scope Issues:
fts_supporters.py:601- Initializesupported_keysbefore conditional blockfts_supporters.py:1201- Movequalnameinitialization outside try blockFixed Type Annotations:
base.py:334- Update_module_specific_freezingparameter type toUnion[torch.nn.Module, Iterable[torch.nn.Module]]fsdp.py:253, 284- Addcast(AbstractContextManager[None], ...)for context manager type inferenceFixed Conditional Imports:
fsdp.py- UseTYPE_CHECKING or torch.distributed.is_available()pattern for FSDP imports_wrap_utils.py- Apply same pattern for consistencyConfiguration Changes
pyproject.toml:
typeCheckingModefrom"basic"to"standard"[tool.mypy]configuration section (will be done in this PR)CI/Testing
New Workflow:
.github/workflows/copilot-setup-steps.ymlfor remote copilot session testinginstall-ci-dependenciescomposite actionTesting
pyright -p pyproject.tomlpasses with 0 errors, 0 warnings, 0 informationstest_fts_explicit_implicitandtest_fts_gen_ft_schedule)Migration Strategy Checklist
This PR follows a systematic approach to complete the pyright migration:
# type: ignorefor deliberate patterns (used sparingly, preferring proper type annotations)Patterns Established
1. Conditional Import Pattern
2. Context Manager Type Casting
3. Variable Initialization Before Conditionals
📚 Documentation preview 📚: https://finetuning-scheduler--23.org.readthedocs.build/en/23/