sooftware / conformer

[Unofficial] PyTorch implementation of "Conformer: Convolution-augmented Transformer for Speech Recognition" (INTERSPEECH 2020)
Apache License 2.0
958 stars 175 forks source link

Remove device from the argument list #34

Closed enhuiz closed 3 years ago

enhuiz commented 3 years ago

This PR solve #33 by removing device from the argument list, which will require the user to manually put input tensors to device as done in the example code in README.

The property solution mentioned in #33 is not adopted as it does work with nn.DataParallel.

When the devices of input tensor and module parameters match, the following to device on the input tensor is not required, which are removed in this PR:

https://github.com/sooftware/conformer/blob/348e8af6c156dae19e311697cbb22b9581880a12/conformer/encoder.py#L117

Besides, as positional encoding is created from a buffer whose device is changed with the module, we don't have to call to device here, which is also removed in this PR.

https://github.com/sooftware/conformer/blob/610a77667aafe533a85001298c522e7079503da4/conformer/attention.py#L147

sooftware commented 3 years ago

Thank you @enhuiz !!