ray icon indicating copy to clipboard operation
ray copied to clipboard

[RLlib] TorchDistributionWrapper Typing Information Should Be Changed

Open mechanyx opened this issue 2 years ago • 4 comments

What happened + What you expected to happen

The code functions but the typing for TorchDistributionWrapper's constructor in torch_action_dist.py should be improved. The code in question is:

    def __init__(self, inputs: List[TensorType], model: TorchModelV2):
        if not isinstance(inputs, torch.Tensor):

The argument typing says you have to pass a list and then on the next line the code checks if it's something that's not a list. Python's isinstance will not check members of collections so isinstance([1,2,3], int) will return False.

So either this function can be expecting inputs to be a Tensor in which case you probably want something like:

def __init__(self, inputs: Union[TensorType, List[TensorType]], model: TorchModelV2):

Or it doesn't in which case the if not isinstance check should be removed as it's always True as a List is not a Tensor.

Versions / Dependencies

This code is currently on HEAD and I found it reading the 2.2 source.

Reproduction script

This is a code/documentation quality/clarity problem, not a functionality issue. You just read the code.

Issue Severity

Low: It annoys or frustrates me.

mechanyx avatar Apr 02 '23 22:04 mechanyx

This P2 issue has seen no activity in the past 2 years. It will be closed in 2 weeks as part of ongoing cleanup efforts.

Please comment and remove the pending-cleanup label if you believe this issue should remain open.

Thanks for contributing to Ray!

cszhu avatar Jun 17 '25 00:06 cszhu

None of the code has been updated so the type hints are still wrong.

mechanyx avatar Jun 17 '25 02:06 mechanyx

I don't believe I have permissions to remove the pending-cleanup tag.

mechanyx avatar Jun 17 '25 02:06 mechanyx

I've removed it. Thanks for the update!

cszhu avatar Jun 17 '25 03:06 cszhu