acids-ircam / nn_tilde

Other
318 stars 34 forks source link

Ratios with a non-two factor cause instant m4l crash #69

Open leoauri opened 8 months ago

leoauri commented 8 months ago

Hi there,

An in_ratio which has some non-two factor seems to cause max for live to instantly crash upon running inference.

For example

class EmptyRatio(nn_tilde.Module):
    def __init__(self, in_channels=1, in_ratio=1, out_channels=1, out_ratio=1):
        super().__init__()

        self.out_channels = out_channels
        self.out_ratio = out_ratio
        self.in_ratio = in_ratio

        self.register_method(
            "forward",
            in_channels=in_channels, 
            in_ratio=in_ratio, 
            out_channels=out_channels, 
            out_ratio=out_ratio,
            test_buffer_size=int(8192/out_ratio*in_ratio)
        )

    @torch.jit.export
    def forward(self, x):
        b, _, l = x.shape
        return torch.zeros(b, self.out_channels, int(l / self.out_ratio * self.in_ratio))

these work

EmptyRatio().export_to_ts('emptyratio.ts')
...
nn~ emptyratio
EmptyRatio(in_ratio=8).export_to_ts('emptyratio8.ts')
...
nn~ emptyratio8

But this crashes instantly:

EmptyRatio(in_ratio=5).export_to_ts('emptyratio5.ts')
...
nn~ emptyratio5

Is that crash unexpected? Is there a technical reason why it cannot work?

Example use case: run encodec decoder (input ratio of 320).

Many thanks,