Hi @mcarilli could you provide a very simple example on how to do it “as is” with libtorch ?
Here’s my training loop right now:
    torch::optim::Adam optim(model->parameters(), torch::optim::AdamOptions(1e-3));
    for(int b=0; b<num_batch; b++)
    {
        optim.zero_grad();
        torch::Tensor result = model(source[b]);
        torch::Tensor loss = torch::l1_loss(result, target);
        loss.backward();
        optim.step();
    }

I’m not sure where to insert the (unofficial) amp calls and how… thanks !
BTW when can we expect a proper libtorch implementation (RAII guard as you mentionned) ?