-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Preload deep learning model #1088
Comments
I have found a solution using a custom worker to pass loaded model to job function
job.py
|
TBH I don't know if you could do any better. This is probably how I would do it as well. Why do you think it's ugly? |
@hnykda It is ugly because I`m violating encapsulation of Worker class changing its args variable. Originally it should represent values passes from the caller "result = q.enqueue(predict, "1.jpeg")" There only one parameter! |
Finally, I understood how this should work. RQ uses importlib.import_module to load function. So every time you call the function it loads jobs file. So as I understand to fix this, you should load this file BEFORE worker execution.
should be replaced with
not this
My final script looks like this
worker.py
|
@Houd1ny I spent many hours trying to figure this out with no luck until I found this issue. Thanks for the help! |
@Houd1ny thanks for the insight, this approached worked for me as well. Sorry for opening the topic again, but I had an additional question. |
By the way, there is also a similar solution here: #720 where you override the work method of a worker. It works with both the normal Worker and the SimpleWorker.
|
If we add the |
@Harsh-Maheshwari You are correct. I did not find a way to have it work with the
Then you can have the
Note: use the |
I have deep learning model that loads into GPU
I want to preload and reuse it every time I execute job.
I have found https://python-rq.org/docs/workers/#performance-notes, but don't know how to access objects from job code
custom_worker.py
job.py
The text was updated successfully, but these errors were encountered: