Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Better error message for tensor with grad as constant in tracing#18298

Closed
eellison wants to merge 2 commits into
pytorch:masterfrom
eellison:const_trace_error
Closed

Better error message for tensor with grad as constant in tracing#18298
eellison wants to merge 2 commits into
pytorch:masterfrom
eellison:const_trace_error

Conversation

@eellison
Copy link
Copy Markdown
Contributor

Fix for #17583

There's an unrelated issue right now causing a segfault when printing tensor so that might have to fixed first for this to land

@eellison eellison requested a review from suo March 21, 2019 23:06
@facebook-github-bot facebook-github-bot added the oncall: jit Add this issue/PR to JIT oncall triage queue label Mar 21, 2019
Comment thread torch/csrc/jit/tracer.cpp Outdated
// Didn't find it. Bake in a constant
if (ten.requires_grad()) {
std::ostringstream oss;
oss << "Cannot insert a Tensor that requires grad as a constant:\n";
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably have a reference to a specific location in the code, as well as possible remediations (trace the module, pass the parameter in explicitly).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have access to where in the code we're at?

Comment thread torch/csrc/jit/tracer.cpp
std::ostringstream oss;
oss << "Cannot insert a Tensor that requires grad as a constant. "
<< "Consider making it a parameter or input, or detaching the gradient\n";
throw std::runtime_error(oss.str());
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to remove the print to tensor because printing calls .contiguous which re-enters the tracer, causing a stack trace failure. That should be fixed but should be in a follow up PR

Copy link
Copy Markdown
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eellison has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

Copy link
Copy Markdown
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eellison has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@suo
Copy link
Copy Markdown
Member

suo commented Mar 23, 2019

This broke trunk, unlanding.

@eellison eellison mentioned this pull request Mar 27, 2019
SuperIRabbit pushed a commit to SuperIRabbit/pytorch that referenced this pull request Mar 27, 2019
Summary:
Trying to reland pytorch#18298
Pull Request resolved: pytorch#18535

Differential Revision: D14652391

Pulled By: eellison

fbshipit-source-id: 699e30045dd5f14f0a2b98378272045a292e1e2a
laurentdupin pushed a commit to laurentdupin/pytorch that referenced this pull request Apr 24, 2026
…orch#18298)

Summary:
Fix for pytorch#17583

There's an unrelated issue right now causing a segfault when printing tensor so that might have to fixed first for this to land
Pull Request resolved: pytorch#18298

Differential Revision: D14584266

Pulled By: eellison

fbshipit-source-id: 4e7850dadc78ef1e98ad40b9d8adc0fef42acf48
laurentdupin pushed a commit to laurentdupin/pytorch that referenced this pull request Apr 24, 2026
Summary:
Trying to reland pytorch#18298
Pull Request resolved: pytorch#18535

Differential Revision: D14652391

Pulled By: eellison

fbshipit-source-id: 699e30045dd5f14f0a2b98378272045a292e1e2a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

oncall: jit Add this issue/PR to JIT oncall triage queue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants