NVIDIA / NVIDIA/apex

Getting ImportError: cannot import name 'FP16_Optimizer' error

Open
#1,013 0 comments 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 am trying to use apex code with this repo - https://github.com/LuoweiZhou/VLP. I have installed the latest version of apex as per the guidelines here. When I try running the repo, I get below error:

Traceback (most recent call last):
  File "vlp/decode_img2txt.py", line 19, in <module>
    from pytorch_pretrained_bert.tokenization import BertTokenizer, WhitespaceTokenizer
  File "/home/default/ephemeral_drive/work/image_captioning/VLP/pytorch_pretrained_bert/__init__.py", line 6, in <module>
    from .optimization_fp16 import FP16_Optimizer_State
  File "/home/default/ephemeral_drive/work/image_captioning/VLP/pytorch_pretrained_bert/optimization_fp16.py", line 4, in <module>
    from apex.optimizers import FP16_Optimizer
ImportError: cannot import name 'FP16_Optimizer'

The recommended commit of apex to use with repo is this - https://github.com/NVIDIA/apex/tree/1603407bf49c7fc3da74fceb6a6c7b47fece2ef8. The possible cause of the error could be that the optimizer that was used with the repo have been replaced with different ones in the latest version of apex. How can I can replace FP16_Optimizer with a suitable optimizer in the latest version of apex without having major changes in the way model is trained?

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 vlp/decode_img2txt.py and pytorch_pretrained_bert/optimization_fp16.py, then compare the repository's pinned Apex commit with the installed Apex version. Reproduce the import failure using the reported traceback and determine whether a supported replacement preserves the existing training behavior. Done means the repository imports and runs without this FP16_Optimizer error.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
machine-learning
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 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.