pykan icon indicating copy to clipboard operation
pykan copied to clipboard

RuntimeError. Problems with dimensions.

Open MDcod opened this issue 9 months ago • 2 comments

Hello! We are trying to plot KAN at initialization:

image

and get error, (where 88 - is length of my set):

RuntimeError                              Traceback (most recent call last)
[<ipython-input-43-31a261174e74>](https://localhost:8080/#) in <cell line: 1>()
----> 1 model(dataset['train_input'])
      2 model.plot(beta=100)

5 frames
[/usr/local/lib/python3.10/dist-packages/kan/KANLayer.py](https://localhost:8080/#) in forward(self, x)
    170         batch = x.shape[0]
    171         # x: shape (batch, in_dim) => shape (size, batch) (size = out_dim * in_dim)
--> 172         x = torch.einsum('ij,k->ikj', x, torch.ones(self.out_dim,).to(self.device)).reshape(batch, self.size).permute(1,0)
    173         preacts = x.permute(1,0).clone().reshape(batch, self.out_dim, self.in_dim)
    174         base = self.base_fun(x).permute(1,0) # shape (batch, size)

RuntimeError: shape '[88, 10]' is invalid for input of size 1320

What could be the problem?

MDcod avatar May 02 '24 06:05 MDcod

dimension of first layer needs adjusting to match dimension of data ingested

gbamin avatar May 02 '24 07:05 gbamin

dimension of first layer needs adjusting to match dimension of data ingested

I actually had this same exact issue yesterday (mixture of this as well as some fat-fingering or .iloc slicing...)

To error-proof this I recommend just making that first dimension dynamic by doing this (using train_input.shape[1] as the first dimension:

image

matthewdillonsmith avatar May 03 '24 12:05 matthewdillonsmith