RuntimeError Traceback (most recent call last)
Cell In[21], line 1
----> 1 d2l.show_heatmaps(attention.attention_weights.reshape((1, 1, 2, 10)),
2 xlabel=‘Keys’, ylabel=‘Queries’)
File ~/anaconda3/envs/LLM/lib/python3.11/site-packages/d2l/torch.py:1146, in show_heatmaps(matrices, xlabel, ylabel, titles, figsize, cmap)
1144 for i, (row_axes, row_matrices) in enumerate(zip(axes, matrices)):
1145 for j, (ax, matrix) in enumerate(zip(row_axes, row_matrices)):
-> 1146 pcm = ax.imshow(d2l.numpy(matrix), cmap=cmap)
1147 if i == num_rows - 1:
1148 ax.set_xlabel(xlabel)
File ~/anaconda3/envs/LLM/lib/python3.11/site-packages/d2l/torch.py:2739, in (x, *args, **kwargs)
2737 abs = torch.abs
2738 eye = torch.eye
-> 2739 numpy = lambda x, *args, **kwargs: x.detach().numpy(*args, **kwargs)
2740 size = lambda x, *args, **kwargs: x.numel(*args, **kwargs)
2741 reshape = lambda x, *args, **kwargs: x.reshape(*args, **kwargs)
RuntimeError: Numpy is not available
/root/anaconda3/envs/LLM/lib/python3.11/site-packages/IPython/core/pylabtools.py:152: MatplotlibDeprecationWarning: savefig() got unexpected keyword argument “facecolor” which is no longer supported as of 3.3 and will become an error two minor releases later
fig.canvas.print_figure(bytes_io, **kw)
/root/anaconda3/envs/LLM/lib/python3.11/site-packages/IPython/core/pylabtools.py:152: MatplotlibDeprecationWarning: savefig() got unexpected keyword argument “edgecolor” which is no longer supported as of 3.3 and will become an error two minor releases later
fig.canvas.print_figure(bytes_io, **kw)
/root/anaconda3/envs/LLM/lib/python3.11/site-packages/IPython/core/pylabtools.py:152: MatplotlibDeprecationWarning: savefig() got unexpected keyword argument “orientation” which is no longer supported as of 3.3 and will become an error two minor releases later
fig.canvas.print_figure(bytes_io, **kw)
解决:torch和numpy版本不匹配:如果是最新版torch,则需要适配最新版numpy,我的是2.0.1cu118的torch,使用最新numpy即可解决。