Skip to content
This repository was archived by the owner on Aug 1, 2025. It is now read-only.
This repository was archived by the owner on Aug 1, 2025. It is now read-only.

Remove .item() calls from optimizer.step() #1083

@yanboliang

Description

@yanboliang

There are a lot of .item() calls inside of optimizer.step(), e.g:
https://github.com/pytorch/pytorch/blob/master/torch/optim/asgd.py#L182-L212

These .item() calls inside of the for loop cause graph break when enabling dynamo and finally hitting cache limit. I took a closer look at these usages and found actually we can remove these call because the results were feed into other downstream tensor operations.
I did a simple verification on ASGD and found removing .item() works well and no graph break on Dynamo end.

I'd like to check if there are other constraints to prevent us from doing this. If not, I can go ahead to fix this.

cc @jansel

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions