Skip to content

Commit

Permalink
aded a simpple test for modal
Browse files Browse the repository at this point in the history
  • Loading branch information
msaroufim committed Nov 19, 2024
1 parent 1dd1899 commit ea64204
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions scripts/modal-test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Run modal token new
# Then run this script as a simple test

# Script executed successfully
# Stopping app - local entrypoint completed.
# tensor([1., 2., 3., 4., 5.], device='cuda:0')
# tensor([1., 2., 3., 4., 5.], device='cuda:0')
# tensor([ 2., 4., 6., 8., 10.], device='cuda:0')

import modal

# Modal app setup
modal_app = modal.App("discord-bot-runner")

@modal_app.function(
gpu="T4",
image=modal.Image.debian_slim(python_version="3.12")
.pip_install(["torch"])
)
async def run_script_on_modal():
"""
Runs a Python script on Modal with GPU
"""
try:
# Define main script content
main_script = """
import sys
import torch
# Your actual script content
a = torch.Tensor([1, 2, 3, 4, 5]).cuda()
b = torch.Tensor([1, 2, 3, 4, 5]).cuda()
print(a)
print(b)
print(a + b)
"""
# Execute the script content directly
exec(main_script, {'__name__': '__main__'})
return "Script executed successfully"
except Exception as e:
return f"Error executing script: {str(e)}"

# Run the function
if __name__ == "__main__":
with modal_app.run():
result = run_script_on_modal.remote()
print(result)

0 comments on commit ea64204

Please sign in to comment.