-
Notifications
You must be signed in to change notification settings - Fork 6
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
tweak examples, add light tests, add gh action #23
Merged
dleviminzi
merged 14 commits into
main
from
dleviminzi/add-environment-for-running-examples
Aug 2, 2024
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
6732686
tweak examples, add light tests, add gh action
dleviminzi b148b5a
remove launch.json
dleviminzi eefd967
remove beta9ignore
dleviminzi 5c43e8c
tweak to run in pr rn
dleviminzi 897a0f5
refactor a bit
dleviminzi fb70f3d
beam auth in action
dleviminzi 201454c
set env
dleviminzi 682e8d4
update deps
dleviminzi df541ce
try unset CI
dleviminzi c8a4b79
try setting manually
dleviminzi 470a417
add workspace id env
dleviminzi e61ccc0
Merge branch 'main' into dleviminzi/add-environment-for-running-examples
dleviminzi 95075ec
merge and update one test
dleviminzi fa7db62
fix test
dleviminzi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
aww