question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Loss automatically detaching inputs breaks some workflows

See original GitHub issue

🐛 Bug description

https://github.com/pytorch/ignite/blob/master/ignite/metrics/loss.py#L60

Before 0.4.3, the y_pred and y were passed without calling detach. Now because of detach a number of usecases are no longer possible.

An example is: https://docs.gpytorch.ai/en/v1.3.1/marginal_log_likelihoods.html#variationalelbo

The output of model(train_x) is an object which does not support detach. This leads to a crash when passing the mll function to Loss as a loss_fn.

Another example is https://github.com/y0ast/deterministic-uncertainty-quantification/blob/master/train_duq_cifar.py#L153

The loss is dependent on the gradient, which means that by calling detach the loss cannot be computed anymore.

I have been trying to work around it, but I can’t figure out a nice way. https://pytorch.org/ignite/metrics.html#ignite.metrics.Average is not input size aware so it cannot correctly compute the average of the loss.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
y0astcommented, Feb 22, 2021

The duq cifar usecase is a bit special. We compute the gradient penalty of https://arxiv.org/abs/1704.00028 also at test time to monitor it. So we can’t use torch.no_grad in the evaluator there.

So the create_supervised_evaluator is not a good fit for it, but I think that’s ok.

0reactions
vfdev-5commented, Feb 22, 2021

Why not call detach on the output of loss_fn?

Yes, it would work. Thanks for the PR, btw !

For your use-case with duq cifar, I assume it is on purpose that evaluator does not have torch.no_grad ? For example, in basic trainings we have it here : https://github.com/pytorch/ignite/blob/442bd08ea93b76e997bbbd190b8b55a7dc29d216/ignite/engine/__init__.py#L460-L465

Read more comments on GitHub >

github_iconTop Results From Across the Web

User Input Breaking my workflow - Designer
Solved: I have a workflow that functions properly (the one ... but do profile the join outputs to ensure you aren't losing any...
Read more >
Troubleshoot common issues with triggers - Power Automate
Here are a few tips and tricks for troubleshooting issues with triggers. ... Verify the flow the inputs and trigger conditions to confirm...
Read more >
Workflow syntax for GitHub Actions
A workflow is a configurable automated process made up of one or more jobs. You must create a YAML file to define your...
Read more >
Common Process Model Workflows and Recipes
This page will highlight some common workflows that are used in many Appian ... If a task or process node is delayed for...
Read more >
Button UI Not Working with The new Input system
After removing that persistent script of my gameobject "MySceneMain" which was including the on click callback action it was fixed. When I run ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found