Simple Modal app example for serving StableLM and Vicuna.
Image generated with Stable Diffusion XL
- Create Modal Account
- Clone App:
git clone https://github.com/triestpa/llm-modal-example.git cd llm-modal-example
- Setup Modal In Local Env:
pip install modal-client modal token new
- Serve App:
or
modal serve stable-lm.py
modal serve vicuna.py
- Generate Completion:
You can also call the model directly with
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"
modal run stable-lm.py
(ormodal run vicuna.py
), which will run themain
function, containing a prompt you can modify.
- 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.
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:
- Download Llama weights
- Follow the instructions here to apply the Vicuna weight deltas to the Llama weights.
- Upload the resulting Vicuna weights to a HuggingFace model repository.
- Generate a HuggingFace access token and add it as a Modal secret called
huggingface-secret
. - Replace
model_name = "triestpa/generated-vicuna-13b"
with the path for the HuggingFace repository. - The
modal run vicuna.py
command should now be able to download and run inference on the Vicuna weights you generated.
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.