Torch.linalg.lstsq: (Batch element 0): Argument 6 has illegal value

CarlosD1119: <p>I have recently been reproducing the <strong>efficient KAN</strong> project [<a href="https://github.com/Blealtan/efficient-kan" class="inline-onebox" rel="noopener nofollow ugc">GitHub - Blealtan/efficient-kan: An efficient pure-PyTorch implementation of Kolmogorov-Arnold Network (KAN).</a>], which uses B-spline curves to replace the traditional activation functions in MLPs. In the project’s ./efficient_kan/kan, the class KANLinear defines a method <code>curve2coeff</code> that involves solving for the coefficients of the interpolation curve using the least squares method, so that the input (x) and output (y) are approximated by a B-spline. However, when running this function, an error occurs with the message as follows. I believe there may have been some issues with the implementation of the numerical computations. The prompt also asks me to report that there might be a bug.</p>
<p>Traceback (most recent call last):<br>
File “C:\Users\Yibin\Downloads\efficient-kan-master\tests\test_simple_math.py”, line 41, in <br>
test_mul()<br>
File “C:\Users\Yibin\Downloads\efficient-kan-master\tests\test_simple_math.py”, line 29, in test_mul<br>
optimizer.step(closure)<br>
File “C:\Users\Yibin.conda\envs\kan_env\lib\site-packages\torch\optim\optimizer.py”, line 487, in wrapper<br>
out = func(*args, **kwargs)<br>
File “C:\Users\Yibin.conda\envs\kan_env\lib\site-packages\torch\utils_contextlib.py”, line 116, in decorate_context<br>
return func(*args, **kwargs)<br>
File “C:\Users\Yibin.conda\envs\kan_env\lib\site-packages\torch\optim\lbfgs.py”, line 330, in step<br>
orig_loss = closure()<br>
File “C:\Users\Yibin.conda\envs\kan_env\lib\site-packages\torch\utils_contextlib.py”, line 116, in decorate_context<br>
return func(*args, **kwargs)<br>
File “C:\Users\Yibin\Downloads\efficient-kan-master\tests\test_simple_math.py”, line 18, in closure<br>
y = kan(x, update_grid=(i % 20 == 0))<br>
File “C:\Users\Yibin.conda\envs\kan_env\lib\site-packages\torch\nn\modules\module.py”, line 1736, in _wrapped_call_impl<br>
return self._call_impl(*args, **kwargs)<br>
File “C:\Users\Yibin.conda\envs\kan_env\lib\site-packages\torch\nn\modules\module.py”, line 1747, in <em>call_impl<br>
return forward_call(*args, **kwargs)<br>
File “C:\Users\Yibin\Downloads\efficient-kan-master\efficient_kan\kan.py”, line 277, in forward<br>
layer.update_grid(x)<br>
File “C:\Users\Yibin.conda\envs\kan_env\lib\site-packages\torch\utils_contextlib.py”, line 116, in decorate_context<br>
return func(*args, **kwargs)<br>
File “C:\Users\Yibin\Downloads\efficient-kan-master\efficient_kan\kan.py”, line 215, in update_grid<br>
self.spline_weight.data.copy</em>(self.curve2coeff(x, unreduced_spline_output))<br>
File “C:\Users\Yibin\Downloads\efficient-kan-master\efficient_kan\kan.py”, line 131, in curve2coeff<br>
solution = torch.linalg.lstsq(<br>
RuntimeError: false INTERNAL ASSERT FAILED at “C:\cb\pytorch_1000000000000\work\aten\src\ATen\native\BatchLinearAlgebra.cpp”:1539, please report a bug to PyTorch. torch.linalg.lstsq: (Batch element 0): Argument 6 has illegal value. Most certainly there is a bug in the implementation calling the backend library.</p>

ptrblck: <p>Which linalg backend and which PyTorch version are you using? If it’s an older release, could you update to the latest stable or nightly binary and rerun your code?</p>

CarlosD1119: <p>I previously used PyTorch version 2.5.1, but even after updating it to the nightly version, the issue still persists. Now it reads:<br>
solution = torch.linalg.lstsq(<br>
RuntimeError: false INTERNAL ASSERT FAILED at “C:\actions-runner\_work\pytorch\pytorch\pytorch\aten\src\ATen\native\BatchLinearAlgebra.cpp”:1604, please report a bug to PyTorch. torch.linalg.lstsq: (Batch element 0): Argument 6 has illegal value. Most certainly there is a bug in the implementation calling the backend library.</p>

ptrblck: <p>Thank you for checking! Are you using a GPU (if so, which device are you using) or the CPU?</p>

CarlosD1119: <p>I tried both GPU(RTX4060Ti) and CPU and both failed.</p>

ptrblck: <p>Could you post a minimal and executable code snippet reproducing the issue, please?</p>