Fix: include root module in parameter calculation#116
Fix: include root module in parameter calculation#116Yui-Arthur wants to merge 1 commit intoultralytics:mainfrom
Conversation
Previously, passing a single layer (e.g., nn.Conv2d) resulted in 0 params because the params of root module was not added.
|
All Contributors have signed the CLA. ✅ |
|
👋 Hello @Yui-Arthur, thank you for submitting a -✅ Define a Purpose: Clearly explain the purpose of your fix or feature in your PR description, and link to any relevant issues. Ensure your commit messages are clear, concise, and adhere to the project's conventions. For more guidance, please refer to our Contributing Guide. This is an automated message, and an engineer will assist soon. 😊🚀 |
UltralyticsAssistant
left a comment
There was a problem hiding this comment.
🔍 PR Review
Made with ❤️ by Ultralytics Actions
PR looks clean. The change correctly aligns parameter counting with ops counting by including the root module’s parameters. No issues found.
I have read the CLA Document and I sign the CLA recheck |
UltralyticsAssistant
left a comment
There was a problem hiding this comment.
🔍 PR Review 2
Made with ❤️ by Ultralytics Actions
Review complete. No issues found in the diff; the change correctly includes root module parameters without introducing problems.
UltralyticsAssistant
left a comment
There was a problem hiding this comment.
🔍 PR Review 3
Made with ❤️ by Ultralytics Actions
Clean change that correctly includes root module parameters in the DFS count. No issues found.
|
I have read the CLA Document and I sign the CLA |
I have read the CLA Document and I sign the CLA
Problem
When passing a single layer (e.g.,
nn.Conv2d) directly toprofile(), the function reports 0 parameters. This happens because the parameter count of the root module itself was ignored during the dfs process.(Fixes #115)
Changes
total_paramswithmodule.total_paramsindfs_count()to ensure the root module's parameters are included.Minimal reproducible example (Issue #115)
Before fix the single layer profile will got zero weights, after fix the profile can get correct weights
🛠️ PR Summary
Made with ❤️ by Ultralytics Actions
🌟 Summary
Fixes parameter counting in
thop/profile.pyby including the root module’s own parameters in the total. 🧮✅📊 Key Changes
-Updates
dfs_count()to initializetotal_paramsfrommodule.total_params.item()instead of0.-Makes parameter aggregation consistent with operation counting (which already includes the current module). 🔧
🎯 Purpose & Impact
-Prevents undercounting parameters for models where the top-level/root module has parameters. 🐛➡️✅
-Improves accuracy and trustworthiness of profiling outputs (params + ops) for end users running THOP profiling. 📈