Skip to content

Instantly share code, notes, and snippets.

@scottsun94
Last active November 8, 2023 09:01
Show Gist options
  • Save scottsun94/e16a5b469b20432adff5d18394f871a6 to your computer and use it in GitHub Desktop.
Save scottsun94/e16a5b469b20432adff5d18394f871a6 to your computer and use it in GitHub Desktop.
import sys
import modal
from modal import Image
ray_image = Image.from_registry("anyscale/ray:2.8.0-py39-cu118")
stub = modal.Stub("example-hello-world")
@stub.function(image=ray_image)
def f(i):
if i % 2 == 0:
print("hello", i)
else:
print("world", i, file=sys.stderr)
return i * i
@stub.local_entrypoint()
def main():
# Call the function locally.
print(f.local(1000))
# Call the function remotely.
print(f.remote(1000))
# Parallel map.
total = 0
for ret in f.map(range(20)):
total += ret
print(total)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment