Skip to content
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

push image #4

Merged
merged 2 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions .github/workflows/build_push_image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ name: "CD: build & push image"

on:
push:
branches: [build-image]
branches:
- build-push-llama3-image
- build-push-phi3-image
workflow_dispatch:

env:
Expand All @@ -12,7 +14,7 @@ env:

jobs:
deploy:
timeout-minutes: 15
timeout-minutes: 30
runs-on:
group: bulkier
steps:
Expand All @@ -31,13 +33,22 @@ jobs:
run: |
python -m pip install transformers torch

- name: Set environment variables based on branch
run: |
if [[ "${{ github.ref }}" == "refs/heads/build-push-llama3-image" ]]; then
echo "MODEL_NAME=llama3" >> $GITHUB_ENV
elif [[ "${{ github.ref }}" == "refs/heads/build-push-phi3-image" ]]; then
echo "MODEL_NAME=phi3" >> $GITHUB_ENV
fi

- name: Docker build and push
run: |
df -h
IMAGE_NAME="${DOCKER_REPO_NAME}:${TAG_VERSION}"
IMAGE_NAME="${DOCKER_REPO_NAME}-{MODEL_NAME}:${TAG_VERSION}"

cd src/compute_horde_prompt_gen

python download_model.py --model_name phi3 --huggingface_token "${{ secrets.HUGGINGFACE_API_KEY }}"
python download_model.py --model_name ${{ env.MODEL_NAME }} --huggingface_token "${{ secrets.HUGGINGFACE_API_KEY }}"

docker build -t $IMAGE_NAME .

docker push $IMAGE_NAME
2 changes: 1 addition & 1 deletion src/compute_horde_prompt_gen/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ RUN mkdir /output

# Copy your Python script into the container
COPY saved_models/ /app/saved_models/
COPY *.py .
COPY *.py ./

# Set the entrypoint to run your script
ENTRYPOINT ["python3", "run.py"]
19 changes: 19 additions & 0 deletions src/compute_horde_prompt_gen/download_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,35 @@
default="./saved_models/",
help="Path to save the model and tokenizer to",
)
parser.add_argument(
"--quantize",
action="store_true",
help="Quantize the model",
default=False,
)

args = parser.parse_args()
save_path = os.path.join(args.save_path, args.model_name)
model_name = MODEL_PATHS[args.model_name]
print(f"Saving {model_name} model to {save_path}")

quantization_config = None
if args.quantize:
import torch
from transformers import BitsAndBytesConfig

quantization_config = BitsAndBytesConfig(
llm_int8_enable_fp32_cpu_offload=False,
load_in_4bit=True,
bnb_4bit_compute_dtype=torch.float16,
)
print("using quantized model")

model = AutoModelForCausalLM.from_pretrained(
model_name,
# either give token directly or assume logged in with huggingface-cli
token=args.huggingface_token or True,
quantization_config=quantization_config,
)
model.save_pretrained(save_path)

Expand Down
4 changes: 2 additions & 2 deletions src/compute_horde_prompt_gen/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,22 @@ def __init__(self):
pass

def generate(self, prompts: list[str], num_return_sequences: int, **_kwargs):
content = f"Here is the list of prompts:\nHow are you?\nDescribe something\nCount to ten\n"
content = "Here is the list of prompts:\nHow are you?\nDescribe something\nCount to ten\n"
return [content for _ in range(len(prompts) * num_return_sequences)]


class GenerativeModel:
def __init__(self, model_path: str, quantize: bool = False):
self.input_prompt_ending = None

import torch
from transformers import (
AutoTokenizer,
AutoModelForCausalLM,
)

quantization_config = None
if quantize:
import torch
from transformers import BitsAndBytesConfig

quantization_config = BitsAndBytesConfig(
Expand Down
Loading