Silent recalculation of result when trying to cache a lambda with dill
See original GitHub issueI have @memory.cache
’d a function that returns a lambda expression. This is not possible to pickle, which makes joblib not cache the result and instead rerun it everytime. dill however is able to pickle such functions, and so I set it as a loky pickler. Yet, the function is still not cached and rerun everytime.
This took me quite a while to find out in two ways. First, to see that if pickling fails, joblib silences this error and does not cache. To mitigate, I use dill as a pickler but that still fails silently.
I would expect
- joblib to crash if it cannot pickle a result, instead of silently going on,
- joblib to crash if I explicitly set a pickler, but that is apparently not used.
I am using joblib-1.1.0, dill-0.3.4 Python 3.9.9 on Mac OS Monterey, M1. Here is what I run:
from joblib.memory import Memory
from joblib.externals.loky import set_loky_pickler
set_loky_pickler('dill')
memory = Memory('./cache')
@memory.cache
def do_stuff():
return lambda: 2
x = do_stuff()
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
Caching data and configuration settings with AWS Lambda ...
This reduces function latency and costs. This post shows how to build both a data and configuration cache using DynamoDB, Parameter Store, and ......
Read more >Can Python pickle lambda functions? - Stack Overflow
try pickle.loads from an other script; I think you pickle the reference to lambda wich, in the same scope, is preserved in memory...
Read more >Lambda: What is the simplest way to cache data ... - Reddit
I'd like to cache the results of some queries, in order to improve performance. For example: count queries, user permission checks, etc.
Read more >InfiniCache: Distributed Cache on Top of AWS Lambda (paper ...
Cloud providers try to reuse compute instances for multiple subsequent requests. The price of bootstrapping new instances is too high to pay for ......
Read more >the of and to a in for is on s that by this with i you it not
... right j type because local those using results office education national g ... put computers journal reports try welcome images central president...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Not with regards to the outputs of functions in mem.cache.
I would agree. We would probably rather use cloud_pickle than dill, because we really in cloud_pickle elsewhere.
Ok, excuse my misunderstanding and thank you for your patience.
I hence take away from the conversation that there currently is no way to make joblib work with lambdas. Doing so would require quite some work in
numpy_pickle
, I suppose.