-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #77 from justinmerrell/starter-examples
feat: prompt cleanup and new starter examples
- Loading branch information
Showing
13 changed files
with
163 additions
and
65 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
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.
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 |
---|---|---|
|
@@ -6,4 +6,3 @@ | |
# To learn more, see https://pip.pypa.io/en/stable/reference/requirements-file-format/ | ||
|
||
<<RUNPOD>> | ||
hf_transfer |
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,14 @@ | ||
# Required Python packages get listed here, one per line. | ||
# Recommended to lock the version number to avoid unexpected changes. | ||
|
||
# You can also install packages from a git repository, e.g.: | ||
# git+https://github.com/runpod/runpod-python.git | ||
# To learn more, see https://pip.pypa.io/en/stable/reference/requirements-file-format/ | ||
|
||
<<RUNPOD>> | ||
hf_transfer | ||
|
||
torch | ||
accelerate | ||
transformers | ||
sentencepiece |
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,36 @@ | ||
''' A starter example for a handler file using RunPod and a large language model for text generation. ''' | ||
|
||
import io | ||
import base64 | ||
from typing import Dict | ||
|
||
import runpod | ||
from transformers import T5Tokenizer, T5ForConditionalGeneration | ||
|
||
# Initialize the tokenizer and model | ||
tokenizer = T5Tokenizer.from_pretrained("google/flan-t5-base") | ||
model = T5ForConditionalGeneration.from_pretrained("google/flan-t5-base", device_map="auto").to("cuda") | ||
|
||
|
||
def handler(job: Dict[str, any]) -> str: | ||
""" | ||
Handler function for processing a job. | ||
Args: | ||
job (dict): A dictionary containing the job input. | ||
Returns: | ||
str: The generated text response. | ||
""" | ||
|
||
job_input = job['input'] | ||
input_text = job_input['text'] | ||
|
||
input_ids = tokenizer(input_text, return_tensors="pt").input_ids.to("cuda") | ||
outputs = model.generate(input_ids) | ||
response = tokenizer.decode(outputs[0]) | ||
|
||
return response | ||
|
||
|
||
runpod.serverless.start({"handler": handler}) |
10 changes: 10 additions & 0 deletions
10
cmd/project/starter_examples/Stable Diffusion/.runpodignore
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,10 @@ | ||
# Similar to .gitignore | ||
# Matches will not be synced to the development pod or cause the development pod to reload. | ||
|
||
Dockerfile | ||
__pycache__/ | ||
*.pyc | ||
.*.swp | ||
.git/ | ||
*.tmp | ||
*.log |
13 changes: 13 additions & 0 deletions
13
cmd/project/starter_examples/Stable Diffusion/builder/requirements.txt
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,13 @@ | ||
# Required Python packages get listed here, one per line. | ||
# Recommended to lock the version number to avoid unexpected changes. | ||
|
||
# You can also install packages from a git repository, e.g.: | ||
# git+https://github.com/runpod/runpod-python.git | ||
# To learn more, see https://pip.pypa.io/en/stable/reference/requirements-file-format/ | ||
|
||
<<RUNPOD>> | ||
hf_transfer | ||
|
||
accelerate | ||
diffusers | ||
transformers |
42 changes: 42 additions & 0 deletions
42
cmd/project/starter_examples/Stable Diffusion/src/handler.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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
''' A starter example for a handler file using RunPod and diffusers for image generation. ''' | ||
|
||
import io | ||
import base64 | ||
from typing import Dict | ||
|
||
import runpod | ||
from diffusers import AutoPipelineForText2Image | ||
import torch | ||
|
||
# Initialize the pipeline | ||
pipe = AutoPipelineForText2Image.from_pretrained( | ||
"stabilityai/sdxl-turbo", # model name | ||
torch_dtype=torch.float16, variant="fp16" | ||
).to("cuda") | ||
|
||
|
||
def handler(job: Dict[str, any]) -> str: | ||
""" | ||
Handler function for processing a job. | ||
Args: | ||
job (dict): A dictionary containing the job input. | ||
Returns: | ||
str: A base64 encoded string of the generated image. | ||
""" | ||
|
||
job_input = job['input'] | ||
prompt = job_input['prompt'] | ||
|
||
image = pipe(prompt=prompt, num_inference_steps=1, guidance_scale=0.0).images[0] | ||
|
||
with io.BytesIO() as buffer: | ||
image.save(buffer, format="PNG") | ||
image_bytes = buffer.getvalue() | ||
base64_image = base64.b64encode(image_bytes).decode('utf-8') | ||
|
||
return f"data:image/png;base64,{base64_image}" | ||
|
||
|
||
runpod.serverless.start({"handler": handler}) |
4 changes: 0 additions & 4 deletions
4
cmd/project/starter_templates/llama2/builder/requirements.txt
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.