Skip to content

Commit

Permalink
updates examples to use new queue and nfs methods
Browse files Browse the repository at this point in the history
  • Loading branch information
charlesfrye committed Mar 21, 2024
1 parent 477a51d commit 8749d14
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 12 deletions.
5 changes: 4 additions & 1 deletion 06_gpu_and_ml/stable_diffusion/a1111_webui.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
from modal import Image, Queue, Stub, forward

stub = Stub("example-a1111-webui")
stub.urls = Queue.new() # TODO: FunctionCall.get() doesn't support generators.
stub.urls = Queue.from_name(
"a1111-webui-example", create_if_missing=True
) # TODO: FunctionCall.get() doesn't support generators.


def wait_for_port(port: int):
Expand Down Expand Up @@ -57,6 +59,7 @@ def wait_for_port(port: int):
.run_commands(
"cd /webui && . venv/bin/activate && "
+ "python -c 'from modules import shared_init, initialize; shared_init.initialize(); initialize.initialize()'",
gpu="a10g",
),
gpu="a10g",
cpu=2,
Expand Down
10 changes: 6 additions & 4 deletions 06_gpu_and_ml/stable_diffusion/stable_video_diffusion.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
import modal

stub = modal.Stub(name="example-stable-video-diffusion-streamlit")
stub.q = modal.Queue.new()
q = modal.Queue.from_name(
"stable-video-diffusion-streamlit", create_if_missing=True
)

session_timeout = 15 * 60

Expand Down Expand Up @@ -68,13 +70,13 @@ def run_streamlit(publish_url: bool = False):
with modal.forward(8501) as tunnel:
# Reload Streamlit config with information about Modal tunnel address.
if publish_url:
stub.q.put(tunnel.url)
q.put(tunnel.url)
load_config_options(
{"browser.serverAddress": tunnel.host, "browser.serverPort": 443}
)
run(
main_script_path="/sgm/scripts/demo/video_sampling.py",
command_line=None,
is_hello=False,
args=["--timeout", str(session_timeout)],
flag_options={},
)
Expand All @@ -86,5 +88,5 @@ def share():
from fastapi.responses import RedirectResponse

run_streamlit.spawn(publish_url=True)
url = stub.q.get()
url = q.get()
return RedirectResponse(url, status_code=303)
2 changes: 1 addition & 1 deletion 06_gpu_and_ml/tensorflow/tensorflow_tutorial.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
# We want to run the web server for TensorBoard at the same time as we are training the TensorFlow model.
# The easiest way to do this is to set up a shared filesystem between the training and the web server.

fs = NetworkFileSystem.new()
fs = NetworkFileSystem.from_name("tensorflow-tutorial", create_if_missing=True)
logdir = "/tensorboard"

# ## Training function
Expand Down
2 changes: 1 addition & 1 deletion 11_notebooks/jupyter_inside_modal.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
)
)
# This volume is not persisted, so the data will be deleted when this demo app is stopped.
volume = modal.NetworkFileSystem.new()
volume = modal.NetworkFileSystem.ephemeral()

CACHE_DIR = "/root/cache"
JUPYTER_TOKEN = "1234" # Change me to something non-guessable!
Expand Down
6 changes: 3 additions & 3 deletions misc/queue_simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import modal.queue

stub = modal.Stub("example-queue-simple")
stub.q = modal.Queue.new()
q = modal.Queue.ephemeral()


@stub.function()
Expand Down Expand Up @@ -51,8 +51,8 @@ async def many_consumers(q: modal.Queue) -> None:

async def main():
with stub.run():
await run_async.remote.aio(stub.q)
await many_consumers.remote.aio(stub.q)
await run_async.remote.aio(q)
await many_consumers.remote.aio(q)


if __name__ == "__main__":
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[tool.pytest.ini_options]
filterwarnings = [
"ignore::DeprecationWarning",
"ignore::modal.exception.DeprecationError",
"error::DeprecationWarning",
"error::modal.exception.DeprecationError",
"ignore::DeprecationWarning:pytest.*:",
]
pythonpath = ["06_gpu_and_ml/spam-detect", "06_gpu_and_ml/text-to-pokemon"]
Expand Down

0 comments on commit 8749d14

Please sign in to comment.