Skip to content

[test] Add error_inputs for nn.Embedding module #174179

@subinz1

Description

@subinz1

Summary

Add module_error_inputs_func for torch.nn.Embedding in common_modules.py to enable regression testing for error messages.

Motivation

Currently, torch.nn.Embedding does not have module_error_inputs_func defined in common_modules.py. This means error message regressions are not tested. Adding error inputs will:

  1. Ensure error messages remain consistent across releases
  2. Test edge cases like out-of-range indices, wrong dtype, etc.
  3. Follow the pattern already established for other modules (BatchNorm, GroupNorm, RNN cells, etc.)

Error Conditions to Test

  1. Out of range indices: Index exceeds num_embeddings

    • Error: IndexError: index out of range in self
  2. Float indices: Float tensor passed instead of integer indices

    • Error: RuntimeError: Expected tensor for argument #1 'indices' to have one of the following scalar types: Long, Int
  3. Negative num_embeddings: Constructor called with negative dimension

    • Error: RuntimeError: Trying to create tensor with negative dimension

Implementation

Add module_error_inputs_torch_nn_Embedding function and wire it to the ModuleInfo entry.

cc @albanD @mruberry @jbschlosser @walterddr @mikaylagawarecki

Metadata

Metadata

Assignees

No one assigned

    Labels

    actionablebot-triagedThis is a label only to be used by the auto triage botenhancementNot as big of a feature, but technically not a bug. Should be easy to fixmodule: nnRelated to torch.nnmodule: testsIssues related to tests (not the torch.testing module)triagedThis issue has been looked at a team member, and triaged and prioritized into an appropriate module

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions