Read torch rand's dtype from the argument that holds it - #2813
Open
LeSingh1 wants to merge 1 commit into
Open
Conversation
aten::rand is rand(size, *, dtype, layout, device, pin_memory), so the
dtype sits right after the size. The converter unpacked
shape, _, dtype, _, _ = _get_inputs(context, node)
which skips the dtype and reads the layout instead. torch always leaves
the layout as None here, so the requested dtype was unreachable and every
torch.rand produced fp32, whatever was asked for.
The lookup was wrong for the same reason: dtype.val is already a torch
dtype number, so NUM_TO_DTYPE_STRING takes it directly, without the
TORCH_DTYPE_TO_NUM step that only made sense for a torch.dtype object.
randn, right below, already reads inputs[1].
The existing test_rand is parametrized over float16 / float32 / float64
but only checks that the samples fall in [0, 1), which holds either way.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Same class as #2809 — an argument read from the wrong position.
aten::randisrand(size, *, dtype, layout, device, pin_memory), so the dtype sits right after the size. The converter unpacked:which skips the dtype and reads the layout. torch always leaves the layout as
Nonehere, so the requested dtype was unreachable and everytorch.randproduced fp32 whatever was asked for. Confirmed by tracing — fortorch.rand(shape, dtype=torch.float16)the constants are[size, 5, None, device(cpu), False], i.e.5(float16) at position 1.The lookup was wrong for the same reason:
dtype.valis already a torch dtype number, soNUM_TO_DTYPE_STRINGtakes it directly, without theTORCH_DTYPE_TO_NUMstep that only made sense for atorch.dtypeobject.randn, right below, already readsinputs[1].The existing
test_randis parametrized over float16 / float32 / float64 but only checks that the samples fall in[0, 1), which holds either way.Testing
TestRand::test_rand_dtypeasserts therandom_uniformdtype in the MIL program. Only the float16 case fails onmain; float32, float64 and the default give fp32 either way and are there as controls. No change in the rand-family failure count (44 pre-existing on this machine, allTorchFrontend.TORCHEXPORTcases hitting a broken local scikit-learn install, which is why I could only exercise TorchScript here).