In RolloutBuffer.compute_returns_and_advantage a numpy array with dtype bool is used as a, operand for subtraction with a python scalar. This relies on some automatic casting rules which pytorch does not support (in particular promoting bool arrays to int/float). When this region is hit by torch-compile a runtime error is encountered. Casting the bool array to an integer dtype resolves the issue.
Description
In
RolloutBuffer.compute_returns_and_advantage
a numpy array with dtype bool is used as a, operand for subtraction with a python scalar. This relies on some automatic casting rules which pytorch does not support (in particular promoting bool arrays to int/float). When this region is hit by torch-compile a runtime error is encountered. Casting the bool array to an integer dtype resolves the issue.After the changes at https://github.com/pytorch/pytorch/pull/124481 land, the example presented in this issue will successfully compile with this small change.
Motivation and Context
This change has no observable impact on the behaviors of programs executed normally. It prevents an error when a user's program uses torch-compile.
If this change is not desired the closed PR will document a work-around for anyone who hits this issue.
Types of changes
Probably the closest option, but I wouldn't classify this as a bug. The issue is only present when a program is manipulated by a 3rd party library.
Checklist
make format
(required)make check-codestyle
andmake lint
(required)make pytest
andmake type
both pass. (required)make doc
(required)Note: You can run most of the checks using
make commit-checks
.Note: we are using a maximum length of 127 characters per line