Is there an example prefect.yaml for a modal work ...
# ask-community
c
Is there an example prefect.yaml for a modal work pool deployment?
1
unsure how everything is connected with modal.stub.function, image creation, etc.
s
Unless I’m misunderstanding, it should look the same as any other work pool
Copy code
deployments:
- name: my-deployment
  version: null
  tags: []
  description: null
  entrypoint: my_flow.py:multiply
  parameters: {}
  work_pool:
    name: my-modal-work-pool
    work_queue_name: null
    job_variables: {}
  schedules: []
I just used
prefect deploy
after creating a Modal push work pool to create a deployment to this work pool and saved the configuration to my
prefect.yaml
c
How is the source code is found? I have a simple setup like this
Copy code
import modal
from prefect import flow


APP_NAME = f"{ENVIRONMENT}-prefect-modal-test"
stub = modal.Stub(APP_NAME)
stub.image = get_image() # custom image


@stub.function(timeout=3600, cloud="aws")
async def test_app():
   return "Success"


@flow
async def run_app():
    await test_app()
and a deployment script like this
Copy code
modal deploy modal_apps/test_modal_app.py

prefect deploy modal_apps/test_modal_app.py -n $ENVIRONMENT-modal-test-app -p $modal_pool_name
j
hey, so the modal integration is using their sandbox api to run individual jobs. You can think of it as, executing flow runs on modal infra with prefect. You can either use a prefect deployment pull step to get your code into the modal container OR specify an image on the work pool itself, for example AWS ECR:
Copy code
deployments:
  ...
  work_pool:
  job_variables: 
     image:
       tag: ... <- AWS ECR TAG
       secret: ... <- modal secret for your AWS creds
prefect doesn't support using the modal python client at this time, so you wouldn't specify things like stub, image, app etc.
c
I see, that makes sense. Wasn't sure how deeply integrated into the modal world you all were.
j
I would say it's a fairly loose integration at the moment, but it does let you harness the power/speed of modal as a infra provider. We're hoping to have some more integrations soon
👍 1
c
Does sandbox make sense for this? That would have a fresh container each time which is somewhat extra overhead
j
definitely some extra overhead for sure if your job is not changing (although modal is very very fast) container based work pools orchestrate a single container per run, with the expectation that the runtime environment can/will change on a per job basis. The sandbox api is most in line with that thinking
a
That would have a fresh container each time which is somewhat extra overhead
IIRC @Jake Kaplan the way the modal sandbox API works there's some intelligent caching in their build steps so not a tremendous amount of overhead
j
yes! their caching is really really good and the overhead would be a couple seconds at most
c
Awesome thanks all. Is there anything that can pull the code in locally or is there only a git/image solution?
j
At the moment you cannot mount your code in a Modal volume or Mount and then select that in your work pool. You can either specify an image and configure it like I showed above or use a prefect pull step to get your code into your container from a remote location git/s3/etc. You can also specify a prefect push step to push your code to this remote location every time you deploy
🙌 1
c
ty ty