From 0a3012cc1a0c8a73a36cf1f6b64b3217ddabb899 Mon Sep 17 00:00:00 2001 From: Michael Waskom Date: Fri, 2 Feb 2024 19:12:34 -0500 Subject: [PATCH] Fix usage of deprecated secret= kwarg (#571) * Fix usage of deprecated secret= kwarg * Run black --- 04_secrets/db_to_sheet.py | 8 ++++---- 05_scheduling/hackernews_alerts.py | 2 +- 06_gpu_and_ml/controlnet/controlnet_gradio_demos.py | 3 ++- 06_gpu_and_ml/embeddings/text_embeddings_inference.py | 4 ++-- 06_gpu_and_ml/embeddings/wikipedia/main.py | 2 +- 06_gpu_and_ml/mini_dalle_slackbot.py | 2 +- .../stable_diffusion/stable_diffusion_aitemplate.py | 2 +- 06_gpu_and_ml/text_generation_inference.py | 6 ++++-- 06_gpu_and_ml/vision_model_training.py | 4 ++-- 06_gpu_and_ml/vllm_inference.py | 4 ++-- 10_integrations/multion_news_agent.py | 2 +- 10_integrations/stable_diffusion_slackbot.py | 6 +++--- misc/news_summarizer.py | 2 +- misc/webscraper.py | 2 +- 14 files changed, 26 insertions(+), 23 deletions(-) diff --git a/04_secrets/db_to_sheet.py b/04_secrets/db_to_sheet.py index 366a17114..9db2dca19 100644 --- a/04_secrets/db_to_sheet.py +++ b/04_secrets/db_to_sheet.py @@ -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"]) @@ -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 @@ -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 @@ -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 diff --git a/05_scheduling/hackernews_alerts.py b/05_scheduling/hackernews_alerts.py index f6923c57b..1434c21c9 100644 --- a/05_scheduling/hackernews_alerts.py +++ b/05_scheduling/hackernews_alerts.py @@ -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 diff --git a/06_gpu_and_ml/controlnet/controlnet_gradio_demos.py b/06_gpu_and_ml/controlnet/controlnet_gradio_demos.py index 16f453d79..06df63737 100644 --- a/06_gpu_and_ml/controlnet/controlnet_gradio_demos.py +++ b/06_gpu_and_ml/controlnet/controlnet_gradio_demos.py @@ -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) diff --git a/06_gpu_and_ml/embeddings/text_embeddings_inference.py b/06_gpu_and_ml/embeddings/text_embeddings_inference.py index c298072c8..1067d0941 100644 --- a/06_gpu_and_ml/embeddings/text_embeddings_inference.py +++ b/06_gpu_and_ml/embeddings/text_embeddings_inference.py @@ -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") ) @@ -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. diff --git a/06_gpu_and_ml/embeddings/wikipedia/main.py b/06_gpu_and_ml/embeddings/wikipedia/main.py index cbacf7405..d579c8b69 100644 --- a/06_gpu_and_ml/embeddings/wikipedia/main.py +++ b/06_gpu_and_ml/embeddings/wikipedia/main.py @@ -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): """ diff --git a/06_gpu_and_ml/mini_dalle_slackbot.py b/06_gpu_and_ml/mini_dalle_slackbot.py index 4ce78250f..f1866fdc6 100644 --- a/06_gpu_and_ml/mini_dalle_slackbot.py +++ b/06_gpu_and_ml/mini_dalle_slackbot.py @@ -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 diff --git a/06_gpu_and_ml/stable_diffusion/stable_diffusion_aitemplate.py b/06_gpu_and_ml/stable_diffusion/stable_diffusion_aitemplate.py index 96b66add2..5179da2ba 100644 --- a/06_gpu_and_ml/stable_diffusion/stable_diffusion_aitemplate.py +++ b/06_gpu_and_ml/stable_diffusion/stable_diffusion_aitemplate.py @@ -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, ) diff --git a/06_gpu_and_ml/text_generation_inference.py b/06_gpu_and_ml/text_generation_inference.py index 5ed75799a..c5ca52916 100644 --- a/06_gpu_and_ml/text_generation_inference.py +++ b/06_gpu_and_ml/text_generation_inference.py @@ -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") ) @@ -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, diff --git a/06_gpu_and_ml/vision_model_training.py b/06_gpu_and_ml/vision_model_training.py index 2142a6e0b..5fb147842 100644 --- a/06_gpu_and_ml/vision_model_training.py +++ b/06_gpu_and_ml/vision_model_training.py @@ -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 @@ -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(): diff --git a/06_gpu_and_ml/vllm_inference.py b/06_gpu_and_ml/vllm_inference.py index bdc40716d..e3554e062 100644 --- a/06_gpu_and_ml/vllm_inference.py +++ b/06_gpu_and_ml/vllm_inference.py @@ -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, ) ) @@ -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 diff --git a/10_integrations/multion_news_agent.py b/10_integrations/multion_news_agent.py index 286cff634..cf148142f 100644 --- a/10_integrations/multion_news_agent.py +++ b/10_integrations/multion_news_agent.py @@ -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 diff --git a/10_integrations/stable_diffusion_slackbot.py b/10_integrations/stable_diffusion_slackbot.py index e9447a633..54deab98f 100644 --- a/10_integrations/stable_diffusion_slackbot.py +++ b/10_integrations/stable_diffusion_slackbot.py @@ -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 @@ -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) @@ -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 diff --git a/misc/news_summarizer.py b/misc/news_summarizer.py index 08039e941..235464f1a 100644 --- a/misc/news_summarizer.py +++ b/misc/news_summarizer.py @@ -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]: diff --git a/misc/webscraper.py b/misc/webscraper.py index c45a30db7..68c97c8aa 100644 --- a/misc/webscraper.py +++ b/misc/webscraper.py @@ -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