Code Monkey home page Code Monkey logo

llm-modal-example's Introduction

LLM Modal Starter

Simple Modal app example for serving StableLM and Vicuna.


Image generated with Stable Diffusion XL

Usage

  1. Create Modal Account
  2. Clone App:
    git clone https://github.com/triestpa/llm-modal-example.git
    cd llm-modal-example
  3. Setup Modal In Local Env:
    pip install modal-client
    modal token new
  4. Serve App:
    modal serve stable-lm.py
    or
    modal serve vicuna.py
  5. Generate Completion:
    Standard:
    HTTP GET https://{modal-app}-get-chat-completion-dev.modal.run?prompt="hello world"
    
    Streaming:
    HTTP GET https://{modal-app}-get-chat-completion-stream-dev.modal.run?prompt="hello world"
    
    You can also call the model directly with modal run stable-lm.py (or modal run vicuna.py), which will run the main function, containing a prompt you can modify.

Startup & Latency

  • The first time it runs, it will take a while for the endpoint to work, as it needs to first download the model and load it into memory. After the first run, the model is cached in persistent storage and the download step will be skipped.
  • On subsequent starts, it will take a couple minutes for the first request to respond while the model is being loaded into memory.
  • After the first request for each run, each completion will be much faster, nearly instant for short responses.
  • If 500 seconds pass without a request, the container will shut down (you'll stop being billed) - and on the next request it will take longer as it will need to load the model back into memory.

Accessing Model Weights

OpenLM should work out-of-the-box as it is completely publically available.

Vicuna is trained from Llama, which has a restricted license that does not allow public distribution.

In order to use Vicuna, the recommended flow is:

  1. Download Llama weights
  2. Follow the instructions here to apply the Vicuna weight deltas to the Llama weights.
  3. Upload the resulting Vicuna weights to a HuggingFace model repository.
  4. Generate a HuggingFace access token and add it as a Modal secret called huggingface-secret.
  5. Replace model_name = "triestpa/generated-vicuna-13b" with the path for the HuggingFace repository.
  6. The modal run vicuna.py command should now be able to download and run inference on the Vicuna weights you generated.

License

Open source MIT license, use this for anything you want.

MIT License

Copyright (c) [2023] [Patrick Triest]

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

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.