Skip to content
This repository has been archived by the owner on Oct 31, 2023. It is now read-only.

Mixed precision training #127

Open
zhiqihuang opened this issue Jan 31, 2022 · 0 comments
Open

Mixed precision training #127

zhiqihuang opened this issue Jan 31, 2022 · 0 comments

Comments

@zhiqihuang
Copy link

I want to use torch mixed precision training with higher. Is there any example code snippet I can follow?

btw, I run code like this:

scaler = torch.cuda.amp.GradScaler()

with higher.innerloop_ctx(model, optim) as (fmodel, diffopt):
    with autocast():
        logits = fmodel(data)
        loss = loss_function(logits, ys)
    scaler.scale(loss).backward()
    scaler.unscale_(diffopt)
    scaler.step(diffopt)
    scaler.update()
    diffopt.zero_grad()

And get the error message

if param.grad is None:
    AttributeError: 'NoneType' object has no attribute 'grad'

at step scaler.unscale_(diffopt)

Thanks for the help.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant