Giter Club home page Giter Club logo

Comments (5)

eightBEC avatar eightBEC commented on May 27, 2024

Hi @mehmetilker
one approach used in this method is to utilize the app's state to share the model within the app.

When talking about distributed workers, you can load the model as a singleton for each worker. For large models I can recommend to prefetch them from an object storage (e.g. S3, COS) to memory (e.g. using Redis), so that each worker can load the model initially.

Does this help?

from fastapi-ml-skeleton.

mehmetilker avatar mehmetilker commented on May 27, 2024

Hi @eightBEC

Using App's state to load an instance for once for the whole application life time but it is meaningful if an application works on single worker.
I am starting my application with following configuration. With the current approach model state loaded to memory separately.
If we have 5 worker process it means 5*1.5GB

command=/home/xproj/.env/bin/gunicorn 
    app.modelsApi.main:app 
    -w 5
    -k uvicorn.workers.UvicornWorker
    --name gunicorn_models_api
    --bind 0.0.0.0:9200

Your advice for the solution (loading from object store to memory) does not change the situation I think, if I understood you right.

Here is another question in SO:
https://stackoverflow.com/questions/41988915/avoiding-loading-spacy-data-in-each-subprocess-when-multiprocessing

I haven't tried but I think related :
https://docs.python.org/3/library/multiprocessing.shared_memory.html
"This module provides a class, SharedMemory, for the allocation and management of shared memory to be accessed by one or more processes on a multicore or symmetric multiprocessor (SMP) machine."

from fastapi-ml-skeleton.

viniciusdsmello avatar viniciusdsmello commented on May 27, 2024

Hi @mehmetilker, have you found a solution for this? I'm facing the same here.

from fastapi-ml-skeleton.

mehmetilker avatar mehmetilker commented on May 27, 2024

@viniciusdsmello no unfortunately...

from fastapi-ml-skeleton.

H3zi avatar H3zi commented on May 27, 2024

You can use gunicorn preload option to download your models only once, the workers fork will happen after the preload.
See this SO answer for more info.
(Haven't tested it with FastAPI)

from fastapi-ml-skeleton.

Related Issues (1)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.