-
Notifications
You must be signed in to change notification settings - Fork 31.1k
Xcodec fix #42095
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Xcodec fix #42095
Conversation
|
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
|
[For maintainers] Suggested jobs to run (before merge) run-slow: xcodec |
| @lru_cache | ||
| def _get_conv1d_layers(self, module): | ||
| """ | ||
| Recursively iterate to fetch all Conv1d layers. | ||
| """ | ||
|
|
||
| def get_conv1d_layers_recursive(module: nn.Module): | ||
| params_list = [] | ||
|
|
||
| if isinstance(module, nn.Conv1d): | ||
| params_list.append(module) | ||
|
|
||
| # Recursively check all child modules | ||
| for child in module.children(): | ||
| params_list.extend(get_conv1d_layers_recursive(child)) | ||
|
|
||
| return params_list | ||
|
|
||
| return tuple(get_conv1d_layers_recursive(module)) | ||
|
|
||
| def _get_conv1d_output_lengths(self, input_length, module=None): | ||
| """ | ||
| For a given module, compute the output length that would be obtained after all Conv1d layers. | ||
| """ | ||
| if module is None: | ||
| module = self | ||
|
|
||
| conv1d_layers = self._get_conv1d_layers(module) | ||
|
|
||
| for layer in conv1d_layers: | ||
| input_length = conv1d_output_length(layer, input_length) | ||
|
|
||
| return input_length |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this something we can do earlier, in the config? It would avoid having to do these recursions on modules etc!
What does this PR do?
Before a deeper clean (#42039) on xcodec and to break things down a bit, this PR fixes some inefficient logic in X-codec, responsible for unnecessary memory spikes.
Makes me think that the whole
_get_output_lengthwhen applying conv1d, which is repeated a lot throughout audio models, could benefit from some standardisation. In that objective, I've added a new audio util that I'll propagate in a subsequent PR.