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.

Need hash_func for type torch._C._TensorBase

See original GitHub issue

Summary

A community member noticed a “cannot hash of type” issue. More information can be found in this forum discussion.

Full error message

This is the info provided by hertzmann:

“UnhashableType: Cannot hash object of type torch._C._TensorBase”.

"I’m trying to cache initialization of a StyleGAN2 class datastructure (which includes loading model weights from a file or online). I don’t want the model weights to be reloaded (and other data structures re-initialized) every time a new image is created.

I tried refactoring my code so that @st.cache is in front of a function that only does one thing: torch.load(filename) and the same error occurs."

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
hertzmanncommented, Apr 2, 2020

Here’s a code snippet that gives the originally-reported error:

import torch
import streamlit as st

@st.cache(allow_output_mutation=True)
def multby2(data):
	return data * 2

st.write(multby2(torch.zeros( (1) )))

which gives:

UnhashableTypeError: Cannot hash object of type torch._C._TensorBase, found in the arguments of multby2().

Note that this variant fails even with allow_output_mutation=True

1reaction
tc87commented, Apr 2, 2020

Hey @hertzmann,

Thanks for providing the above 🙏. Going to circle back with the team with the new info and then will get back to you, but might not be able to respond before next week. If not, hope you have a nice weekend and will reach back out soon.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Pytorch class torch._C.TensorBase information?
I am wondering from where the tensor._c.TensorBase comes from?Can Someone please tell me the c source ...
Read more >
Class Tensor — PyTorch master documentation
This function returns the forward gradient for this Tensor at the given level. void _set_fw_grad (const TensorBase &new_grad, uint64_t level, bool is_inplace_op) ...
Read more >
Torch Core - fastai
Show all images ims as subplots with rows using titles . Type, Default, Details. ims. nrows, int, 1 ...
Read more >
Simple index - piwheels
... fdi flask-bootstraps apachecn-c-cpp-zh-pt2 pdb2af django-geoposition javaoneliner pipe21 taichi types-aiobotocore-mediaconvert tradinghalts-02 nzbsort ...
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