NVIDIA / NVIDIA/apex

Type casting of module input

Open
#435 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
9k
Forks
1.5k
Avg merge
2d 4h
Merged PRs (30d)
3

Description

I have a torch.nn.module implementation whose forward pass accepts as input a custom class structure that is inherited from a dict. All values of this object are torch Tensors.

The problem is that when I wrap my model with amp.initialize() and use amp level 02, the input which my model receives is a standard dict.

I managed to trace this issue to line 203 of the _initialize.py script: https://github.com/NVIDIA/apex/blob/master/apex/amp/_initialize.py#L203

The signature of the function is def new_fwd(*args, **kwargs): which means that my input class is broken up into a standard dict and the custom structure is lost.

Can anyone suggest a way around this? Preferably without having to modify the apex code itself.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with apex/amp/_initialize.py at line 203 and reproduce the report using a dict subclass whose values are torch Tensors, then wrap the model with amp.initialize() at amp level O2. Compare the input type received by forward before and after wrapping. Done means establishing whether the custom structure can be preserved or identifying a documented workaround that avoids modifying Apex.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, pytorch
Domain
machine-learning
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.