St.experimental_memo TypeError: cannot pickle 'weakref' object

Hi, I am trying to use st.experimental_memo but I’m getting TypeError: cannot pickle ‘weakref’ object
What could be wrong?

Hi @OOlajide, welcome to the community! :wave:

I wasn’t able to reproduce the error on my end with streamlit==1.0.0 and transformers==4.11.3.

What versions of streamlit and transformers are you using? That info will help with debugging. Also, could you share the entire traceback?

Have you tried using @st.experimental_singleton? It is used is for storing non-data objects, including TensorFlow/Torch/Keras sessions:

Best, :balloon:
Snehan

My streamlit version is 1.0.0 and transformers is 4.11.3. I haven’t tried using st.experimental_singleton. Although, st.cache works just fine but I am trying to leverage the speed of the new caching primitives. I’ve attached the full traceback.

Hey OOlajide - we really need to make that error message better!

This issue here is that the pipeline object you’re creating is not a “pure data” object, and it can’t be serialized. Snehan’s suggestion to use @st.experimental_singleton is correct - you want to use singleton when you’re storing a non-data object that performs computation, and st.experimental_memo when you’re storing data that is the result of a computation.