question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Argmax unexpected key and Cant convert Cuda tensor to Numpy error

See original GitHub issue

Hi I am facing the issue below. I have installed fast-bert using pip and just copied the code from the readme. Any suggestions on how to fix?

model/tensorboard
Traceback (most recent call last):
  File "/usr1/home/rjoshi2/envs/myenv/lib/python3.7/site-packages/numpy/core/fromnumeric.py", line 61, in _wrapfunc
    return bound(*args, **kwds)
TypeError: argmax() got an unexpected keyword argument 'axis'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "train_bert.py", line 67, in <module>
    main()
  File "train_bert.py", line 62, in main
    optimizer_type="lamb")
  File "/usr1/home/rjoshi2/envs/myenv/lib/python3.7/site-packages/fast_bert/learner_cls.py", line 406, in fit
    results = self.validate()
  File "/usr1/home/rjoshi2/envs/myenv/lib/python3.7/site-packages/fast_bert/learner_cls.py", line 524, in validate
    all_logits, all_labels
  File "/usr1/home/rjoshi2/envs/myenv/lib/python3.7/site-packages/fast_bert/metrics.py", line 15, in accuracy
    outputs = np.argmax(y_pred, axis=1)
  File "<__array_function__ internals>", line 6, in argmax
  File "/usr1/home/rjoshi2/envs/myenv/lib/python3.7/site-packages/numpy/core/fromnumeric.py", line 1153, in argmax
    return _wrapfunc(a, 'argmax', axis=axis, out=out)
  File "/usr1/home/rjoshi2/envs/myenv/lib/python3.7/site-packages/numpy/core/fromnumeric.py", line 70, in _wrapfunc
    return _wrapit(obj, method, *args, **kwds)
  File "/usr1/home/rjoshi2/envs/myenv/lib/python3.7/site-packages/numpy/core/fromnumeric.py", line 47, in _wrapit
    result = getattr(asarray(obj), method)(*args, **kwds)
  File "/usr1/home/rjoshi2/envs/myenv/lib/python3.7/site-packages/numpy/core/_asarray.py", line 85, in asarray
    return array(a, dtype, copy=False, order=order)
  File "/usr1/home/rjoshi2/envs/myenv/lib/python3.7/site-packages/torch/tensor.py", line 433, in __array__
    return self.numpy()
TypeError: can't convert CUDA tensor to numpy. Use Tensor.cpu() to copy the tensor to host memory first.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:8

github_iconTop GitHub Comments

1reaction
talhaanwarchcommented, Jan 2, 2020

facing same issue in lastest version, i belived its 1.60 , i am using google colab

1reaction
josh-coopercommented, Dec 15, 2019

This occurs with the new version released today. Try pip installling version 1.5.0.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Argmax unexpected key and Cant convert Cuda tensor to ...
Hi I am facing the issue below. I have installed fast-bert using pip and just copied the code from the readme. Any suggestions...
Read more >
can't convert CUDA tensor to numpy. Use Tensor.cpu() to copy ...
to index = output.cpu().data.numpy().argmax(). This means data is first moved to cpu and then converted to numpy array.
Read more >
can't convert CUDA tensor to numpy. Use Tensor.cpu() to copy ...
cpu() to copy the tensor to host memory first. TypeError: can't convert CUDA tensor to numpy. Use Tensor. cpu() to copy the tensor...
Read more >
torch.Tensor — PyTorch master documentation
Current implementation of torch.Tensor introduces memory overhead, thus it might lead to unexpectedly high memory usage in the applications with many tiny ...
Read more >
CuPy Documentation - Read the Docs
CuPy is a NumPy/SciPy-compatible array library for GPU-accelerated computing with Python. CuPy acts as a drop-in.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found