Last active
November 8, 2023 09:01
-
-
Save scottsun94/e16a5b469b20432adff5d18394f871a6 to your computer and use it in GitHub Desktop.
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 | |
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