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
# Let's say you have a method `map(f, inputs)` that performs some operation on inputs | |
# Let's also sayu that this function returns a generator. | |
# A user might pass a function f that has some side effect, e.g. `def f(x): print(x)` | |
# This might lead to confusing results if the output is never consumed: | |
# `map(f, inputs)` -> this does nothing, can be confusing to the user | |
# `list(map(f, inputs))` -> this executes `f` on all inputs | |
# To remedy the situation, we can provide a helpful warning to the user if the generator | |
# is never consumed. | |
### Helper code: |
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
import io | |
import modal | |
stub = modal.Stub(image=modal.DebianSlim().pip_install(["prophet"])) | |
@stub.function | |
def run(): | |
import pandas as pd | |
from prophet import Prophet | |
from matplotlib import pyplot |
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
# Note: this assumes you have a notebook locally named my_notebook.ipynb | |
import modal | |
stub = modal.Stub( | |
image=modal.DebianSlim().pip_install(["papermill", "ipykernel"]), | |
mounts=[modal.Mount(local_file="my_notebook.ipynb", remote_dir="/root")], | |
) | |
@stub.function |
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
import json | |
import subprocess | |
import sys | |
import tempfile | |
import modal | |
stub = modal.Stub() | |
stub.sv = modal.SharedVolume().persist("valhalla") | |
image = modal.DockerhubImage("valhalla/valhalla:run-latest", setup_commands=["apt-get update", "apt-get install -y python3-pip"]) |
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
import io | |
import sys | |
import modal | |
stub = modal.Stub( | |
image=modal.Image.debian_slim() | |
.apt_install(["git"]) | |
.pip_install( | |
[ |
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
if __name__ == "__main__": | |
secret = modal.Secret({"FOO": os.environ["FOO"]}) | |
else: | |
secret = modal.Secret.from_name("baz") |
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
import sys | |
import modal | |
stub = modal.Stub( | |
image=modal.Image.debian_slim().pip_install(["datasets", "torch", "transformers"]) | |
) | |
class Predictor: |
OlderNewer