Skip to content
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

export error v2.3.1 #275

Open
chrizzlemadizzle opened this issue Dec 22, 2023 · 4 comments
Open

export error v2.3.1 #275

chrizzlemadizzle opened this issue Dec 22, 2023 · 4 comments

Comments

@chrizzlemadizzle
Copy link

Hey! I'm receiving an error when trying to export a model with v2.3.1 using the following configs:

!/content/miniconda/bin/rave preprocess --input_path $dataset --output_path $preprocessed_dataset --channels 2 !/content/miniconda/bin/rave train --config v3 --config wasserstein --db_path $preprocessed_dataset --name $name --val_every 500 --channels 2

!/content/miniconda/bin/rave export --run $model_dir --streaming --channels 2 --fidelity 0.999

the error:

INFO:root:library loading INFO:root:DEBUG I1222 19:43:17.716103 140450175820864 export.py:495] building rave /content/miniconda/lib/python3.9/site-packages/torch/nn/utils/weight_norm.py:30: UserWarning: torch.nn.utils.weight_norm is deprecated in favor of torch.nn.utils.parametrizations.weight_norm. warnings.warn("torch.nn.utils.weight_norm is deprecated in favor of torch.nn.utils.parametrizations.weight_norm.") /content/miniconda/lib/python3.9/site-packages/torchaudio/transforms/_transforms.py:94: UserWarning: return_complex argument is now deprecated and is not effective.torchaudio.transforms.Spectrogram(power=None) always returns a tensor with complex dtype. Please remove the argument in the function call. warnings.warn( I1222 19:43:19.216365 140450175820864 export.py:505] model found : /content/drive/MyDrive/AI/RAVE/vivaZweiTraining/2023-12-22-testing2-3-1/runs/viva_35fc26584b/version_0/checkpoints/epoch-epoch=0020.ckpt Traceback (most recent call last): File "/content/miniconda/bin/rave", line 8, in <module> sys.exit(main()) File "/content/miniconda/lib/python3.9/site-packages/scripts/main_cli.py", line 38, in main app.run(export.main) File "/content/miniconda/lib/python3.9/site-packages/absl/app.py", line 308, in run _run_main(main, args) File "/content/miniconda/lib/python3.9/site-packages/absl/app.py", line 254, in _run_main sys.exit(main(argv)) File "/content/miniconda/lib/python3.9/site-packages/scripts/export.py", line 513, in main pretrained.load_state_dict( File "/content/miniconda/lib/python3.9/site-packages/torch/nn/modules/module.py", line 2152, in load_state_dict raise RuntimeError('Error(s) in loading state_dict for {}:\n\t{}'.format( RuntimeError: Error(s) in loading state_dict for RAVE: size mismatch for encoder.encoder.net.0.weight_v: copying a param with shape torch.Size([96, 32, 7]) from checkpoint, the shape in current model is torch.Size([96, 16, 7]). size mismatch for decoder.net.32.weight_g: copying a param with shape torch.Size([64, 1, 1]) from checkpoint, the shape in current model is torch.Size([32, 1, 1]). size mismatch for decoder.net.32.weight_v: copying a param with shape torch.Size([64, 96, 7]) from checkpoint, the shape in current model is torch.Size([32, 96, 7]). size mismatch for discriminator.discriminators.0.convs.0.0.weight_v: copying a param with shape torch.Size([32, 2, 5, 1]) from checkpoint, the shape in current model is torch.Size([32, 1, 5, 1]). size mismatch for discriminator.discriminators.1.convs.0.0.weight_v: copying a param with shape torch.Size([32, 2, 5, 1]) from checkpoint, the shape in current model is torch.Size([32, 1, 5, 1]). size mismatch for discriminator.discriminators.2.convs.0.0.weight_v: copying a param with shape torch.Size([32, 2, 5, 1]) from checkpoint, the shape in current model is torch.Size([32, 1, 5, 1]). size mismatch for discriminator.discriminators.3.convs.0.0.weight_v: copying a param with shape torch.Size([32, 2, 5, 1]) from checkpoint, the shape in current model is torch.Size([32, 1, 5, 1]). size mismatch for discriminator.discriminators.4.convs.0.0.weight_v: copying a param with shape torch.Size([32, 2, 5, 1]) from checkpoint, the shape in current model is torch.Size([32, 1, 5, 1]). size mismatch for discriminator.discriminators.5.band_convs.0.0.0.weight_v: copying a param with shape torch.Size([32, 4, 3, 9]) from checkpoint, the shape in current model is torch.Size([32, 2, 3, 9]). size mismatch for discriminator.discriminators.5.band_convs.1.0.0.weight_v: copying a param with shape torch.Size([32, 4, 3, 9]) from checkpoint, the shape in current model is torch.Size([32, 2, 3, 9]). size mismatch for discriminator.discriminators.5.band_convs.2.0.0.weight_v: copying a param with shape torch.Size([32, 4, 3, 9]) from checkpoint, the shape in current model is torch.Size([32, 2, 3, 9]). size mismatch for discriminator.discriminators.5.band_convs.3.0.0.weight_v: copying a param with shape torch.Size([32, 4, 3, 9]) from checkpoint, the shape in current model is torch.Size([32, 2, 3, 9]). size mismatch for discriminator.discriminators.5.band_convs.4.0.0.weight_v: copying a param with shape torch.Size([32, 4, 3, 9]) from checkpoint, the shape in current model is torch.Size([32, 2, 3, 9]). size mismatch for discriminator.discriminators.6.band_convs.0.0.0.weight_v: copying a param with shape torch.Size([32, 4, 3, 9]) from checkpoint, the shape in current model is torch.Size([32, 2, 3, 9]). size mismatch for discriminator.discriminators.6.band_convs.1.0.0.weight_v: copying a param with shape torch.Size([32, 4, 3, 9]) from checkpoint, the shape in current model is torch.Size([32, 2, 3, 9]). size mismatch for discriminator.discriminators.6.band_convs.2.0.0.weight_v: copying a param with shape torch.Size([32, 4, 3, 9]) from checkpoint, the shape in current model is torch.Size([32, 2, 3, 9]). size mismatch for discriminator.discriminators.6.band_convs.3.0.0.weight_v: copying a param with shape torch.Size([32, 4, 3, 9]) from checkpoint, the shape in current model is torch.Size([32, 2, 3, 9]). size mismatch for discriminator.discriminators.6.band_convs.4.0.0.weight_v: copying a param with shape torch.Size([32, 4, 3, 9]) from checkpoint, the shape in current model is torch.Size([32, 2, 3, 9]). size mismatch for discriminator.discriminators.7.band_convs.0.0.0.weight_v: copying a param with shape torch.Size([32, 4, 3, 9]) from checkpoint, the shape in current model is torch.Size([32, 2, 3, 9]). size mismatch for discriminator.discriminators.7.band_convs.1.0.0.weight_v: copying a param with shape torch.Size([32, 4, 3, 9]) from checkpoint, the shape in current model is torch.Size([32, 2, 3, 9]). size mismatch for discriminator.discriminators.7.band_convs.2.0.0.weight_v: copying a param with shape torch.Size([32, 4, 3, 9]) from checkpoint, the shape in current model is torch.Size([32, 2, 3, 9]). size mismatch for discriminator.discriminators.7.band_convs.3.0.0.weight_v: copying a param with shape torch.Size([32, 4, 3, 9]) from checkpoint, the shape in current model is torch.Size([32, 2, 3, 9]). size mismatch for discriminator.discriminators.7.band_convs.4.0.0.weight_v: copying a param with shape torch.Size([32, 4, 3, 9]) from checkpoint, the shape in current model is torch.Size([32, 2, 3, 9]).

@augustross3
Copy link

Having this same error when exporting on v2.3

@spwilson2
Copy link

Yeah, I'm seeing issues exporting any models w/ two channels. Single channel seems to work fine.

@spwilson2
Copy link

spwilson2 commented Jan 21, 2024

In mycase it looks like the following wasn't stored in the generated .gin files for some reason:

model.RAVE.n_channels = 2

When I added that to the .gin file half of the reported errors went away and I was left w/

Traceback (most recent call last):
  File "C:\Users\spwil\AppData\Local\Programs\Python\Python310\Scripts\rave-script.py", line 33, in <module>
    sys.exit(load_entry_point('acids-rave==2.3.1', 'console_scripts', 'rave')())
  File "C:\Users\spwil\AppData\Local\Programs\Python\Python310\lib\site-packages\scripts\main_cli.py", line 38, in main
    app.run(export.main)
  File "C:\Users\spwil\AppData\Local\Programs\Python\Python310\lib\site-packages\absl\app.py", line 308, in run
    _run_main(main, args)
  File "C:\Users\spwil\AppData\Local\Programs\Python\Python310\lib\site-packages\absl\app.py", line 254, in _run_main
    sys.exit(main(argv))
  File "C:\Users\spwil\AppData\Local\Programs\Python\Python310\lib\site-packages\scripts\export.py", line 514, in main
    pretrained.load_state_dict(
  File "C:\Users\spwil\AppData\Local\Programs\Python\Python310\lib\site-packages\torch\nn\modules\module.py", line 1671, in load_state_dict
    raise RuntimeError('Error(s) in loading state_dict for {}:\n\t{}'.format(
RuntimeError: Error(s) in loading state_dict for RAVE:
        size mismatch for latent_pca: copying a param with shape torch.Size([16, 16]) from checkpoint, the shape in current model is torch.Size([2, 2]).
        size mismatch for latent_mean: copying a param with shape torch.Size([16]) from checkpoint, the shape in current model is torch.Size([2]).
        size mismatch for fidelity: copying a param with shape torch.Size([16]) from checkpoint, the shape in current model is torch.Size([2]).

That I was able to workaround with that with the following patch on top of v2.3.1:

diff --git a/rave/model.py b/rave/model.py
index d30002b..38b06fc 100644
--- a/rave/model.py
+++ b/rave/model.py
@@ -192,7 +192,7 @@ class RAVE(pl.LightningModule):
         self.multiband_audio_distance = multiband_audio_distance()

         self.gan_loss = gan_loss
-
+        latent_size = 16
         self.register_buffer("latent_pca", torch.eye(latent_size))
         self.register_buffer("latent_mean", torch.zeros(latent_size))
         self.register_buffer("fidelity", torch.zeros(latent_size))

Edit:
It does seem to work with the M4L nn~ object, so this at least works as a workaround for now...

@maksimay
Copy link

maksimay commented Mar 22, 2024

Same for me thanks so much for the workaround.

I also managed to export my 3channel model with this fix

adding model.RAVE.n_channels = 3 in the config.gin
and by changing the lines of the export.py accordingly:


self.register_method(
          "encode",
          in_channels=3, #my number of channels
          in_ratio=1,
          out_channels=3, #my number of channels
          out_ratio=ratio_encode,
          input_labels=['(signal) Input audio signal'],
          output_labels=[
              f'(signal) Latent dimension {i}'
              for i in range(self.latent_size)
          ],
      )
      self.register_method(
          "decode",
          in_channels=3, #my number of channels
          in_ratio=ratio_encode,
          out_channels=3, #my number of channels
          out_ratio=1,
          input_labels=[
              f'(signal) Latent dimension {i}'
              for i in range(self.latent_size)
          ],
          output_labels=[
              f'(signal) Reconstructed audio signal {channel}'
              for channel in channels
          ],
      )

      self.register_method(
          "forward",
          in_channels=3, #my number of channels
          in_ratio=1,
          out_channels=3, #my number of channels
          out_ratio=1,
          input_labels=['(signal) Input audio signal'],
          output_labels=[
              f'(signal) Reconstructed audio signal {channel}'
              for channel in channels
          ],
      )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants