Repository navigation
Conversation
detectron2onnx imported onnxruntime.quantization at module load, which loads all of onnx, and base.py imports detectron2onnx for every model, including YOLOX. visualize imported matplotlib.pyplot, and layout.py imports visualize for draw_bbox. Neither library is needed unless a quantized Detectron2 model is created or show_plot is called, so import each at its single call site. Importing the layout and model modules drops from 367 MiB to 149 MiB RSS. A 16-page YOLOX run's peak RSS drops from 1013 MiB to 792 MiB with identical output. Co-authored-by: wtfyd-agent[bot] <328989958+wtfyd-agent[bot]@users.noreply.github.com>
This was referenced Oct 24, 2026
Contributor
Author
|
Combined effect of #530, #531, #532 and #533 merged together onto
|
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.
Summary
Importing the layout API loaded two large libraries that most runs never use:
models/detectron2onnx.pyimportedonnxruntime.quantizationat module load, which loads all ofonnx.models/base.pyimportsdetectron2onnxfor every model, YOLOX included, but quantization only runs when a quantized Detectron2 model doesn't exist on disk yet.visualize.pyimportedmatplotlib.pyplot, andinference/layout.pyimportsvisualizefordraw_bbox. Onlyshow_plotuses matplotlib.Each import now happens at its single call site.
Impact
Measured on macOS, Python 3.13:
inference.layout+models.baseprocess_file_with_model)The YOLOX run produced identical output (161 elements) on both sides.
Verification
test_unstructured_inference/test_imports.pyimportsinference.layout,models.base,models.detectron2onnxandvisualizein a fresh interpreter and asserts that neitheronnxnormatplotlibgets loaded. It fails onmainand passes here.show_plottests still patchmatplotlib.pyplot.subplots/showand pass, because the module attributes are looked up at call time.make test: 383 passed, 1 skipped.ruff check/ruff format --checkclean.Version bumped to 1.6.17 with a CHANGELOG entry. #530 also targets 1.6.17, so whichever merges second needs the next patch version.