Skip to content

ZeroDivisionError in backward #26

Closed
@furybubu

Description

@furybubu

Hi, I am having an error when I implement the amp procedure on a working CNN like this:

self.optimizer.zero_grad()

        outputs = self.model(maps)

        loss = self.criterion(outputs,labels.float())

        #add automatic mixed precision support from apex
        with self.amp_handle.scale_loss(loss, self.optimizer) as scaled_loss:

            scaled_loss.backward()

        self.optimizer.step()

`
And here is the error I get:

scaled_loss.backward() File "/usr/lib/python3.5/contextlib.py", line 66, in __exit__ next(self.gen) File "/usr/local/lib/python3.5/dist-packages/apex-0.1-py3.5-linux-x86_64.egg/apex/amp/handle.py", line 53, in scale_loss optimizer.param_groups, loss_scale) File "/usr/local/lib/python3.5/dist-packages/apex-0.1-py3.5-linux-x86_64.egg/apex/amp/scaler.py", line 21, in unscale_and_update 1. / scale, ZeroDivisionError: float division by zero

Any suggestion would be appreciated.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions