Skip to content

Commit

Permalink
Fix usage of deprecated secret= kwarg (#571)
Browse files Browse the repository at this point in the history
* Fix usage of deprecated secret= kwarg

* Run black
  • Loading branch information
mwaskom authored Feb 3, 2024
1 parent 55497df commit 0a3012c
Show file tree
Hide file tree
Showing 14 changed files with 26 additions and 23 deletions.
8 changes: 4 additions & 4 deletions 04_secrets/db_to_sheet.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
stub = modal.Stub("example-db-to-sheet")


@stub.function(secret=modal.Secret.from_name("postgres-secret"))
@stub.function(secrets=[modal.Secret.from_name("postgres-secret")])
def my_func():
# automatically filled from the specified secret
print("Host is " + os.environ["PGHOST"])
Expand All @@ -73,7 +73,7 @@ def my_func():

@stub.function(
image=pg_image,
secret=modal.Secret.from_name("postgres-secret"),
secrets=[modal.Secret.from_name("postgres-secret")],
)
def get_db_rows():
import psycopg2
Expand All @@ -100,7 +100,7 @@ def get_db_rows():

@stub.function(
image=requests_image,
secret=modal.Secret.from_name("weather-secret"),
secrets=[modal.Secret.from_name("weather-secret")],
)
def city_weather(city):
import requests
Expand Down Expand Up @@ -169,7 +169,7 @@ def main():

@stub.function(
image=pygsheets_image,
secret=modal.Secret.from_name("gsheets-secret"),
secrets=[modal.Secret.from_name("gsheets-secret")],
)
def update_sheet_report(rows):
import pygsheets
Expand Down
2 changes: 1 addition & 1 deletion 05_scheduling/hackernews_alerts.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@


@stub.function(
image=slack_sdk_image, secret=modal.Secret.from_name("hn-bot-slack")
image=slack_sdk_image, secrets=[modal.Secret.from_name("hn-bot-slack")]
)
async def post_to_slack(message: str):
import slack_sdk
Expand Down
3 changes: 2 additions & 1 deletion 06_gpu_and_ml/controlnet/controlnet_gradio_demos.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,8 @@ def download_demo_files() -> None:
)
.apt_install("ffmpeg", "libsm6", "libxext6")
.run_function(
download_demo_files, secret=Secret.from_dict({"DEMO_NAME": DEMO_NAME})
download_demo_files,
secrets=[Secret.from_dict({"DEMO_NAME": DEMO_NAME})],
)
)
stub = Stub(name="example-controlnet", image=image)
Expand Down
4 changes: 2 additions & 2 deletions 06_gpu_and_ml/embeddings/text_embeddings_inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def download_model():
.run_function(
download_model,
gpu=GPU_CONFIG,
secret=Secret.from_name("huggingface-secret"),
secrets=[Secret.from_name("huggingface-secret")],
)
.pip_install("httpx")
)
Expand All @@ -84,7 +84,7 @@ def download_model():


@stub.cls(
secret=Secret.from_name("huggingface-secret"),
secrets=[Secret.from_name("huggingface-secret")],
gpu=GPU_CONFIG,
image=tei_image,
# Use up to 20 GPU containers at once.
Expand Down
2 changes: 1 addition & 1 deletion 06_gpu_and_ml/embeddings/wikipedia/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ def upload_result_to_hf(batch_size: int) -> None:
CHECKPOINT_DIR: EMBEDDING_CHECKPOINT_VOLUME,
},
timeout=86400,
secret=Secret.from_name("huggingface-secret"),
secrets=[Secret.from_name("huggingface-secret")],
)
def embed_dataset(down_scale: float = 1, batch_size: int = 512 * 50):
"""
Expand Down
2 changes: 1 addition & 1 deletion 06_gpu_and_ml/mini_dalle_slackbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def load_model(device=None):

@stub.function(
image=Image.debian_slim().pip_install("slack-sdk"),
secret=Secret.from_name("dalle-bot-slack-secret"),
secrets=[Secret.from_name("dalle-bot-slack-secret")],
)
def post_to_slack(prompt: str, channel_name: str, image_bytes: bytes):
import slack_sdk
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ def _inference(
)
.run_function(
download_and_compile,
secret=modal.Secret.from_name("huggingface-secret"),
secrets=[modal.Secret.from_name("huggingface-secret")],
timeout=60 * 30,
gpu=GPU_TYPE,
)
Expand Down
6 changes: 4 additions & 2 deletions 06_gpu_and_ml/text_generation_inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@ def download_model():
tgi_image = (
Image.from_registry("ghcr.io/huggingface/text-generation-inference:1.0.3")
.dockerfile_commands("ENTRYPOINT []")
.run_function(download_model, secret=Secret.from_name("huggingface-secret"))
.run_function(
download_model, secrets=[Secret.from_name("huggingface-secret")]
)
.pip_install("text-generation")
)

Expand All @@ -112,7 +114,7 @@ def download_model():


@stub.cls(
secret=Secret.from_name("huggingface-secret"),
secrets=[Secret.from_name("huggingface-secret")],
gpu=GPU_CONFIG,
allow_concurrent_inputs=10,
container_idle_timeout=60 * 10,
Expand Down
4 changes: 2 additions & 2 deletions 06_gpu_and_ml/vision_model_training.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def download_dataset():
# utilization.
#
# If you want to run this example without setting up Weights & Biases, just remove the
# `secret=Secret.from_name("wandb")` line from the Function decorator below; this will disable Weights & Biases
# `secrets=[Secret.from_name("wandb")]` line from the Function decorator below; this will disable Weights & Biases
# functionality.
#
# ### Detaching our training run
Expand All @@ -135,7 +135,7 @@ def download_dataset():
image=image,
gpu=USE_GPU,
network_file_systems={str(MODEL_CACHE): volume},
secret=Secret.from_name("wandb"),
secrets=[Secret.from_name("wandb")],
timeout=2700, # 45 minutes
)
def train():
Expand Down
4 changes: 2 additions & 2 deletions 06_gpu_and_ml/vllm_inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def download_model_to_folder():
.env({"HF_HUB_ENABLE_HF_TRANSFER": "1"})
.run_function(
download_model_to_folder,
secret=Secret.from_name("huggingface-secret"),
secrets=[Secret.from_name("huggingface-secret")],
timeout=60 * 20,
)
)
Expand All @@ -82,7 +82,7 @@ def download_model_to_folder():
# on the GPU for each subsequent invocation of the function.
#
# The `vLLM` library allows the code to remain quite clean.
@stub.cls(gpu="A100", secret=Secret.from_name("huggingface-secret"))
@stub.cls(gpu="A100", secrets=[Secret.from_name("huggingface-secret")])
class Model:
def __enter__(self):
from vllm import LLM
Expand Down
2 changes: 1 addition & 1 deletion 10_integrations/multion_news_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@


@stub.function(
image=multion_image, secret=modal.Secret.from_name("MULTION_API_KEY")
image=multion_image, secrets=[modal.Secret.from_name("MULTION_API_KEY")]
)
def news_tweet_agent():
# Import MultiOn
Expand Down
6 changes: 3 additions & 3 deletions 10_integrations/stable_diffusion_slackbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def fetch_model(local_files_only: bool = False):
"ftfy",
"accelerate",
)
.run_function(fetch_model, secret=Secret.from_name("huggingface-secret"))
.run_function(fetch_model, secrets=[Secret.from_name("huggingface-secret")])
)

# ### The actual function
Expand All @@ -98,7 +98,7 @@ def fetch_model(local_files_only: bool = False):
@stub.function(
gpu="A10G",
image=image,
secret=Secret.from_name("huggingface-secret"),
secrets=[Secret.from_name("huggingface-secret")],
)
async def run_stable_diffusion(prompt: str, channel_name: Optional[str] = None):
pipe = fetch_model(local_files_only=True)
Expand Down Expand Up @@ -165,7 +165,7 @@ async def entrypoint(request: Request):

@stub.function(
image=Image.debian_slim().pip_install("slack-sdk"),
secret=Secret.from_name("stable-diff-slackbot-secret"),
secrets=[Secret.from_name("stable-diff-slackbot-secret")],
)
def post_image_to_slack(title: str, channel_name: str, image_bytes: bytes):
import slack_sdk
Expand Down
2 changes: 1 addition & 1 deletion misc/news_summarizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class NYArticle:


@stub.function(
secret=modal.Secret.from_name("nytimes"),
secrets=[modal.Secret.from_name("nytimes")],
image=scraping_image,
)
def latest_science_stories(n_stories: int = 5) -> List[NYArticle]:
Expand Down
2 changes: 1 addition & 1 deletion misc/webscraper.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ async def get_links(url: str) -> set[str]:

@stub.function(
image=slack_sdk_image,
secret=modal.Secret.from_name("scraper-slack-secret"),
secrets=[modal.Secret.from_name("scraper-slack-secret")],
)
def bot_token_msg(channel, message):
import slack_sdk
Expand Down

0 comments on commit 0a3012c

Please sign in to comment.