Skip to content

Include module name and type in validation error messages#823

Open
RohithVangalla1 wants to merge 2 commits into
meta-pytorch:mainfrom
RohithVangalla1:fix/module-validator-include-module-name-in-errors
Open

Include module name and type in validation error messages#823
RohithVangalla1 wants to merge 2 commits into
meta-pytorch:mainfrom
RohithVangalla1:fix/module-validator-include-module-name-in-errors

Conversation

@RohithVangalla1

@RohithVangalla1 RohithVangalla1 commented May 22, 2026

Copy link
Copy Markdown

Previously, validation errors from ModuleValidator.validate() did not indicate which specific sub-module caused the failure. For models with many layers, this made debugging DP compatibility issues difficult — users had to manually inspect each layer to find the offending module.

This change prepends the module path and type to each validation error message. For example, instead of:
'BatchNorm cannot support DP'
users now see:
'encoder.layer.3.norm (BatchNorm2d): BatchNorm cannot support DP'

This makes it immediately clear which layer needs to be replaced, especially in large models with hundreds of sub-modules.

Addresses the TODO:
'use module name here - it's useful part of error message'

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Docs change / refactoring / dependency upgrade

Motivation and Context / Related issue

How Has This Been Tested (if it applies)

Checklist

  • The documentation is up-to-date with the changes I made.
  • I have read the CONTRIBUTING document and completed the CLA (see CONTRIBUTING).
  • All tests passed, and additional code has been covered with new tests.

Previously, validation errors from ModuleValidator.validate() did not
indicate which specific sub-module caused the failure. For models with
many layers, this made debugging DP compatibility issues difficult —
users had to manually inspect each layer to find the offending module.

This change prepends the module path and type to each validation error
message. For example, instead of:
  'BatchNorm cannot support DP'
users now see:
  'encoder.layer.3.norm (BatchNorm2d): BatchNorm cannot support DP'

This makes it immediately clear which layer needs to be replaced,
especially in large models with hundreds of sub-modules.

Addresses the TODO:
  'use module name here - it's useful part of error message'
@meta-cla

meta-cla Bot commented May 22, 2026

Copy link
Copy Markdown

Hi @RohithVangalla1!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@iden-kalemaj

Copy link
Copy Markdown
Contributor

@RohithVangalla1 thank you for this PR, can you please include a small unit test that verifies the desired error message output?

Added two tests to module_validator_test.py:

- test_validate_error_includes_module_name: verifies that a simple
  model with a BatchNorm1d named 'bn' produces an error containing
  both the module name ('bn') and type ('BatchNorm1d')

- test_validate_error_includes_nested_module_name: verifies that a
  nested model produces an error with the full dotted path
  ('block.norm') and type ('BatchNorm1d')
@RohithVangalla1

Copy link
Copy Markdown
Author

Hi @iden-kalemaj , Thank you so much for the review:

Added two unit tests in a2ab7e5:

  • test_validate_error_includes_module_name: A simple model with nn.BatchNorm1d named "bn" — verifies the error message contains both "bn" and "BatchNorm1d"
  • test_validate_error_includes_nested_module_name: A nested model with block.norm path — verifies the error contains the full dotted path "block.norm" and "BatchNorm1d"

Example of the new error output:
bn (BatchNorm1d): Batch normalization cannot support DP ...
block.norm (BatchNorm1d): Batch normalization cannot support DP ...

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