Spaces:
Running on Zero
Running on Zero
Download lscodec/models/fairseq_modules/transpose_last.py from ALWOAL/focalcodec-quantization: direct link, hf CLI and curl.
- Browser
- Download file 623 Bytes
-
https://huggingface.co/spaces/ALWOAL/focalcodec-quantization/resolve/main/lscodec/models/fairseq_modules/transpose_last.py
- Command line
-
hf download hf://spaces/ALWOAL/focalcodec-quantization/lscodec/models/fairseq_modules/transpose_last.py
-
curl -L -o transpose_last.py https://huggingface.co/spaces/ALWOAL/focalcodec-quantization/resolve/main/lscodec/models/fairseq_modules/transpose_last.py
623 Bytes
| # Copyright (c) Facebook, Inc. and its affiliates. | |
| # | |
| # This source code is licensed under the MIT license found in the | |
| # LICENSE file in the root directory of this source tree. | |
| """ | |
| transpose last 2 dimensions of the input | |
| """ | |
| import torch.nn as nn | |
| class TransposeLast(nn.Module): | |
| def __init__(self, deconstruct_idx=None, tranpose_dim=-2): | |
| super().__init__() | |
| self.deconstruct_idx = deconstruct_idx | |
| self.tranpose_dim = tranpose_dim | |
| def forward(self, x): | |
| if self.deconstruct_idx is not None: | |
| x = x[self.deconstruct_idx] | |
| return x.transpose(self.tranpose_dim, -1) | |