Skip to content

num_quantizer in EncodecConfig should accept variable codebook size #34521

@mindmapper15

Description

@mindmapper15

System Info

transformers == 4.46.1

Who can help?

No response

Information

  • The official example scripts
  • My own modified scripts

Tasks

  • An officially supported task in the examples folder (such as GLUE/SQuAD, ...)
  • My own task or dataset (give details below)

Reproduction

I pretrained custom EnCodec model of my own and trying to convert it to huggingface model format
I used a different codebook size in my custom EnCodec model such as 4096 or 8192 (the default is 1024)

Here is the problem :
The user can change the codebook size in EncodecConfig by passing the argument.
When the num_quantizer is calculated however, the codebook size is fixed to default value 1024.

@property
def num_quantizers(self) -> int:
return int(1000 * self.target_bandwidths[-1] // (self.frame_rate * 10))

Here, 10 multiplied with self.frame_rate, which stands for the number of bit consumed by the codebook size, is fixed.

Expected behavior

num_quantizer should accept variable codebook size since we can already change the codebook size in argument.
Here is the modified code based on official implementation.

    @property
    def num_quantizers(self) -> int:
        return int(max(1, math.floor(self.target_bandwidths[-1] * 1000 / self.frame_rate *  math.log2(self.codebook_size))))

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions