Fix wav2vec2 ONNX export when layer drop is disabled - #4214
Conversation
…orch.onnx.export()` Closes pytorch#4116
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/audio/4214
Note: Links to docs will display an error until the docs builds have been completed. This comment was automatically generated by Dr. CI and updates every 15 minutes. |
|
Hi @saisharan0103! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
Fixes #4116.
Wav2Vec2ModelONNX export could fail for freshly constructedwav2vec2_xlsr_300mmodels because they are in training mode by default whileencoder_layer_dropis0.0. In that state,Transformer.forwardstill evaluatedtorch.rand(1).item()before deciding whether to skip a layer, sotorch.onnx.export(..., dynamo=True)encountered Python scalar extraction from a random tensor even though layer dropping was disabled.This changes the layer-drop gate to short-circuit before creating a random tensor when the module is not training or when
self.layer_dropis0.0, while preserving stochastic layer skipping for positive layer-drop values during training.A focused regression test was added for ONNX export of a very small
wav2vec2_modelconfigured withencoder_layer_drop=0.0and left in training mode, guarded for the optional ONNX export dependencies.ruff check src/torchaudio/models/wav2vec2/components.py test/torchaudio_unittest/models/wav2vec2/model_test.pyreports no new findings on the changed files.Ran
pytest -xlocally with no new failures.