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 contextlib | |
import OpenSSL.crypto | |
import os | |
import requests | |
import ssl | |
import tempfile | |
@contextlib.contextmanager | |
def pfx_to_pem(pfx_path, pfx_password): | |
''' Decrypts the .pfx file to be used with requests. ''' |
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
from matplotlib import pyplot | |
import random | |
import time | |
pyplot.style.use("ggplot") | |
now = time.time() | |
def generate_user(censor=now): | |
# Pick some point in time the user was created | |
t_created = t = now - random.random() * 1e7 |
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
# Note – this is not a bash script (some of the steps require reboot) | |
# I named it .sh just so Github does correct syntax highlighting. | |
# | |
# This is also available as an AMI in us-east-1 (virginia): ami-cf5028a5 | |
# | |
# The CUDA part is mostly based on this excellent blog post: | |
# http://tleyden.github.io/blog/2014/10/25/cuda-6-dot-5-on-aws-gpu-instance-running-ubuntu-14-dot-04/ | |
# Install various packages | |
sudo apt-get update |
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 sys | |
import modal | |
stub = modal.Stub( | |
image=modal.Image.debian_slim().pip_install(["datasets", "torch", "transformers"]) | |
) | |
class Predictor: |
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 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 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
# 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: |
NewerOlder