Skip to content

[Lint] Fix all remaining ruff warnings, type errors and asserts in src - #300

Open
LinusJungemann wants to merge 2 commits into
devfrom
refactor/ruff_v2
Open

LinusJungemann wants to merge 2 commits into
devfrom
refactor/ruff_v2

Conversation

@LinusJungemann

Copy link
Copy Markdown
Member

Supersedes #262: the same change, ported onto the #257 port (refactor/custom_ops_v2) and current dev. Depends on the custom-ops PR; review that one first. Until it is merged, this PR's diff also contains its two commits.

Problem

#262 finishes the cleanup that #257 started for the custom ops:

  • all of src/ passes ruff and pyright;
  • assert is no longer used for error handling;
  • ruff replaces flake8 in pre-commit.

It was written against the same 819-commit-old dev as #257. Since then dev has changed 15 of the files #262 touches. It has also added a lot of code #262 never saw: QoR estimation, resource models, torch_hw_modules, PWPolyF/Pad1D/Where/SelectToken/Requant conversion, multi-FPGA, MLO DDR weight offsets. With ruff now gating every file under src/ in CI, all of that code has to be clean too.

Changes

Testing

Lint:

  • pre-commit run --all-files is clean, including ruff on all of src/.
  • pyright src reports 0 errors.
  • There are 0 assert statements in src/.

Follow-ups

🤖 Generated with Claude Code

Port of #262 onto the custom-op refactor branch (#257
port) and current dev. #262's own changes were re-applied file by file with
dev's functional changes kept, and the same cleanup was done for the code
dev added after #262 was written (QoR estimation, resource models,
torch_hw_modules, the convert_to_hw transforms for PWPolyF/Pad1D/Where/
SelectToken/Requant, multi-FPGA, MLO/DDR weight offsets, ...).

- src/ is ruff-clean (ruff-check pre-commit hook, v0.15.10, on ^src/), which
  replaces flake8 (.flake8 removed)
- pyright reports 0 errors for src/
- no assert statements left in src/: FINNUserError for invalid input,
  FINNInternalError for broken invariants
- the docstring-check GitHub action is removed, ruff's D rules cover it

Behaviour is unchanged apart from exception types for invalid input, with
these exceptions:
- AuroraPartitioner: the connections_per_device constraint now sums over the
  right nodes (from #262), so ports_per_device actually limits partitions
- fold_quant_weights: #262's new "unknown output shape" check is only applied
  to Conv/ConvTranspose targets, where the shape is used; applying it to all
  targets broke MatMul folding (test_brevitas_pwpolyf)
- build_dataflow_steps: unlike #262, the Vitis platform is still resolved for
  single-FPGA Alveo builds before any transformation runs

Merge fixes: streamline_plus imported #262's AbsorbSignBiasIntoMultiThreshold
but called dev's renamed AbsorbScalarBiasIntoMultiThreshold (NameError);
multi_dnn imported DNNContainer from the old abstract/ path.

Verification: pre-commit --all-files clean, pyright 0 errors and 0 asserts in
src/. Differential checks against the previous version for data_packing
(11k pack/unpack cases, byte-identical), resource models (1.39M cases), QoR
estimators, torch_hw_modules, generated TCL/driver code (AST comparison), and
targeted fast tests for every touched area.

Signed-off-by: Linus Jungemann <38974033+LinusJungemann@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@bwintermann bwintermann added this to the FINN+ 1.6.2 milestone Oct 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants