-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tweak examples, add light tests, add gh action (#23)
* tweak examples, add light tests, add gh action * remove launch.json * remove beta9ignore * tweak to run in pr rn * refactor a bit * beam auth in action * set env * update deps * try unset CI * try setting manually * add workspace id env * merge and update one test * fix test
- Loading branch information
1 parent
9203bda
commit a065cd4
Showing
56 changed files
with
4,081 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
name: Tests | ||
|
||
on: [push, pull_request, workflow_dispatch] | ||
|
||
jobs: | ||
light-test: | ||
runs-on: ubuntu-latest | ||
env: | ||
BEAM_AUTH_TOKEN: ${{ secrets.BEAM_AUTH_TOKEN }} | ||
BEAM_WORKSPACE_ID: ${{ secrets.BEAM_WORKSPACE_ID }} | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: set up python | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: '3.x' | ||
|
||
- name: install poetry | ||
uses: snok/install-poetry@v1 | ||
with: | ||
version: '1.5.1' | ||
virtualenvs-create: true | ||
virtualenvs-in-project: true | ||
|
||
- name: load cached venv | ||
id: cached-poetry-dependencies | ||
uses: actions/cache@v3 | ||
with: | ||
path: .venv | ||
key: venv-${{ runner.os }}-${{ hashFiles('**/poetry.lock') }} | ||
|
||
- name: install dependencies | ||
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true' | ||
run: poetry install --no-interaction --no-root | ||
|
||
- name: configure beam | ||
run: | | ||
source .venv/bin/activate | ||
mkdir -p ~/.beam | ||
cat << EOF > ~/.beam/config.ini | ||
[default] | ||
token = ${{ secrets.BEAM_AUTH_TOKEN }} | ||
gateway_host = gateway.beam.cloud | ||
gateway_port = 443 | ||
EOF | ||
- name: run tests | ||
run: | | ||
source .venv/bin/activate | ||
pytest tests/light_test.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,5 @@ | |
__pycache__ | ||
__downloads__ | ||
.env | ||
.venv | ||
.venv | ||
.vscode/launch.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
1 change: 0 additions & 1 deletion
1
...ation/sdxl-turbo-streaming/backend/app.py → ...ation/sdxl-turbo-streaming/backend/app.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
from beam import endpoint, Image | ||
from beam import Image, Volume, endpoint, Output | ||
|
||
CACHE_PATH = "./models" | ||
|
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
""" | ||
### Mixtral 7B ### | ||
Note: This is a gated Huggingface model and you must request access to it here: | ||
https://huggingface.co/mistralai/Mistral-7B-v0.1 | ||
Retrieve your HF token from this page: https://huggingface.co/settings/tokens | ||
After your access is granted, make sure to save your Huggingface token on Beam: | ||
``` | ||
$ beam secret create [SECRET] | ||
``` | ||
...and add the secret to your Beam function decorator: | ||
@endpoint(secrets=["HF_TOKEN"]) | ||
""" | ||
|
||
from beam import endpoint, Image, Volume, env | ||
|
||
# This ensures that these packages are only loaded when the script is running remotely on Beam | ||
if env.is_remote(): | ||
import torch | ||
from transformers import AutoModelForCausalLM, AutoTokenizer | ||
|
||
CHECKPOINT = "mistralai/Mistral-7B-v0.1" | ||
BEAM_VOLUME_PATH = "./cached_models" | ||
|
||
|
||
def load_models(): | ||
model = AutoModelForCausalLM.from_pretrained( | ||
CHECKPOINT, | ||
torch_dtype=torch.float16, | ||
device_map="auto", | ||
cache_dir=BEAM_VOLUME_PATH, | ||
) | ||
tokenizer = AutoTokenizer.from_pretrained(CHECKPOINT) | ||
return model, tokenizer | ||
|
||
|
||
@endpoint( | ||
secrets=["HF_TOKEN"], | ||
on_start=load_models, | ||
name="mistral-7b", | ||
cpu=2, | ||
memory="32Gi", | ||
gpu="A10G", | ||
image=Image( | ||
python_version="python3.11", | ||
python_packages=[ | ||
"transformers==4.42.3", | ||
"sentencepiece==0.1.99", | ||
"accelerate==0.23.0", | ||
"torch==2.0.1", | ||
], | ||
), | ||
volumes=[ | ||
Volume( | ||
name="cached_models", | ||
mount_path=BEAM_VOLUME_PATH, | ||
) | ||
], | ||
) | ||
def generate(context, **inputs): | ||
# Retrieve model and tokenizer from on_start | ||
model, tokenizer = context.on_start_value | ||
|
||
# Inputs passed to API | ||
prompt = inputs.get("prompt") | ||
if not prompt: | ||
return {"error": "Please provide a prompt."} | ||
|
||
generate_args = { | ||
"max_new_tokens": inputs.get("max_new_tokens", 128), | ||
"temperature": inputs.get("temperature", 1.0), | ||
"top_p": inputs.get("top_p", 0.95), | ||
"top_k": inputs.get("top_k", 50), | ||
"repetition_penalty": 1.0, | ||
"no_repeat_ngram_size": 0, | ||
"use_cache": True, | ||
"do_sample": True, | ||
"eos_token_id": tokenizer.eos_token_id, | ||
"pad_token_id": tokenizer.pad_token_id, | ||
} | ||
|
||
input_ids = tokenizer(prompt, return_tensors="pt").input_ids.cuda() | ||
|
||
with torch.no_grad(): | ||
output = model.generate(inputs=input_ids, **generate_args) | ||
generated_text = tokenizer.decode(output[0], skip_special_tokens=True) | ||
|
||
return {"generated_text": generated_text} |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.