Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversHalloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix Now×
Skip to content
World desk13 min

How to deploy a machine-learning model on Modal with serverless GPUs

A practical guide to deploying machine-learning inference on Modal: define the image and GPU in Python, validate with modal run, deploy persistent HTTP services, package weights, integrate MLflow and plan for memory, latency, scaling and cost.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The shortest path to GPU inference on Modal is to declare the container image, Python dependencies, GPU type and model function in one Python file, then run that file with modal run. When the function works, modal deploy turns it into a persistent application. For HTTP traffic, expose the function through a Modal Server or web-server function; for MLflow models, the Modal plugin can package artifacts, place them in a Volume, create FastAPI routes and return an HTTPS endpoint.

This approach moves container building, GPU provisioning and autoscaling into Modal while you pay for active resource usage. You still have to make the model fit the selected GPU, control cold-start behavior, persist large weights sensibly and validate the deployed API under your real concurrency pattern.

As an Amazon Associate I earn from qualifying purchases.

What a Modal GPU deployment actually contains

A Modal application is infrastructure described in Python rather than a manually maintained virtual machine. The file defines four things that matter to inference:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • Image: the operating-system base and installed packages.
  • Execution unit: the function or server that receives work.
  • GPU: the accelerator attached to that unit, such as an H100 or A100.
  • Invocation model: an on-demand function for jobs and experiments, or a persistent HTTP service for API traffic.

Modal builds the image, starts a compatible container when work arrives, attaches the requested accelerator and tears resources down when they are no longer needed. Its documentation describes this as serverless execution and per-second usage billing: Modal operates the underlying hosts while your code specifies the environment. GPU availability, limits and prices can change, so treat the GPU name in a file as a request, not a permanent capacity guarantee.

#1 Best Overall
ASUS Dual Radeon RX 9060 XT 16GB GDDR6 Gaming Graphics Card | PCIe 5.0, HDMI 2.1b, DisplayPort 2.1a, 2.5-slot design, Axial-tech Fans, 0dB Technology
  • Axial-tech fans now feature a smaller fan hub that facilitates longer blades and a barrier ring that increases downward air pressure
  • 2.5-slot design allows for greater build compatibility while maintaining cooling performance
  • 0dB technology lets you enjoy light gaming in relative silence
  • Dual BIOS switch lets you toggle between Quiet and Performance BIOS profiles
  • Dual ball fan bearings last up to twice as long as sleeve bearing designs

The distinction between a one-off invocation and a deployed service is important. modal run is the development and verification path; modal deploy registers a persistent application that can expose HTTP routes and remain available for callers.

Prerequisites and account setup

  1. Create a Modal account. GPU execution requires a valid payment method on the account.
  2. Install the SDK. In the Python environment where you will edit the application, run pip install modal.
  3. Authenticate the CLI. Run modal setup and complete the browser-based authentication flow.
  4. Prepare a local project. Keep the Modal Python file, any application code, a dependency lockfile if you use one, and a clear model-configuration file together. Do not rely on packages that happen to be installed on your laptop; the remote image is the runtime that matters.

Run the setup commands from the same environment you will use to invoke the application. If your shell cannot find modal, activate the intended virtual environment or install the package into the interpreter that owns your project.

Build the smallest working GPU application

The official minimal pattern starts with a modal.App, creates a Debian-based image, installs the Transformers framework with its PyTorch extra, and attaches an H100 to the inference function. The model is initialized inside that remote GPU container, not on the machine issuing the command.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
import modal

app = modal.App("text-classifier")

image = (
    modal.Image.debian_slim()
    .uv_pip_install("transformers[torch]")
)

@app.function(gpu="h100", image=image)
def classify(text: str):
    from transformers import pipeline

    classifier = pipeline(
        "sentiment-analysis",
        model="distilbert-base-uncased-finetuned-sst-2-english",
        device_map="cuda",
    )
    return classifier(text)

This example demonstrates the deployment shape rather than a production optimization. Loading the pipeline inside the function guarantees that CUDA-dependent initialization happens in the GPU-backed container. In a real service, avoid rebuilding the model for every request: initialize it in a container-startup or lifecycle hook supported by the SDK version you have installed, then reuse the in-memory object for subsequent calls in that warm container.

Why device_map="cuda" matters

Transformers must place the model on the accelerator. A CPU-only image or a function that initializes before the GPU is attached can produce device errors, silently move work to the CPU or exhaust host memory. Keep GPU-specific imports and initialization in the remote function or its supported startup hook, and verify that the framework version in the image supports the selected CUDA runtime.

Pin dependencies for repeatable builds

Use explicit versions for the model framework, tokenizer and serving libraries when reproducibility matters. Rebuild the image after changing dependencies; an already-created image will not automatically include a package added to your local environment. Large optional libraries should be installed only when the model needs them, because every extra layer increases build time and may increase cold-start transfer time.

Package model code, dependencies and weights

There are three common weight-delivery strategies. Select one deliberately instead of allowing a production container to depend on an undocumented local cache.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Download weights during startup

The function can download a model from its registry the first time a container starts. This keeps the image smaller and makes model updates independent of image builds, but the first request pays for network transfer and startup. Use this pattern for experimentation or models that are small enough to initialize quickly. Cache the downloaded files in the container when the platform reuses that container; caching does not make the data durable across all future containers.

Rank #2
GIGABYTE GeForce RTX 5070 Ti Gaming OC 16G Graphics Card, 16GB 256-bit GDDR7, PCIe 5.0, WINDFORCE Cooling System, GV-N507TGAMING OC-16GD Video Card
  • Powered by the NVIDIA Blackwell architecture and DLSS 4
  • Powered by GeForce RTX 5070 Ti
  • Integrated with 16GB GDDR7 256bit memory interface
  • PCIe 5.0
  • WINDFORCE cooling system

Bake weights into the image

Installing or copying weights during image construction makes startup more predictable after the image is available. The trade-off is a large image, slower builds and a new image build whenever weights change. This is practical when the artifact is stable and startup latency is more important than build speed.

Store weights in a Modal Volume

A Volume separates model artifacts from the image and is useful when several server instances need the same files. Mount the Volume using the current Modal SDK syntax, upload or materialize the weights once, and have the server read them from the mounted path. Confirm that the model code handles a missing or partially populated Volume; a deployment should fail clearly rather than attempt an expensive download on every request.

For all three approaches, package tokenizer files, configuration, custom Python modules and any generation templates along with the weights. A checkpoint without its tokenizer or preprocessing code is not a deployable model.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Validate locally with modal run

Save the application as, for example, inference.py, then invoke it from the project directory:

modal run inference.py

Use this phase to check four failure boundaries before exposing an endpoint:

  1. The image builds and all imports resolve.
  2. The requested GPU is available to your account and the model initializes without an out-of-memory error.
  3. Representative inputs produce the expected schema, labels or generated text.
  4. Initialization and inference complete within the timeout and memory limits you intend to use.

modal run is an invocation of your development entry point; it is not a permanently addressable production service. It is therefore the right place to print tensor shapes, inspect one result and test a smaller sample before you commit to an always-on API design.

Deploy a persistent application with modal deploy

When the function behaves correctly, deploy the file:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
modal deploy inference.py

Modal registers the application and, for HTTP routes, reports a URL. Official examples also expose interactive Swagger documentation for deployed routes. Treat the URL as an operational credential: restrict access with the authentication mechanism your application requires, and do not publish it in source control or client-side code without an access plan.

Rank #3
GIGABYTE GeForce RTX 5060 WINDFORCE OC 8G Graphics Card, Cooling System, 8GB 128-bit GDDR7, PCIe 5.0, Manufactured by NVIDIA, DisplayPort & HDMI - Video Output Interface, GV-N5060WF2OC-8GD Video Card
  • Powered by the NVIDIA Blackwell architecture and DLSS 4
  • Powered by GeForce RTX 5060
  • Integrated with 8GB GDDR7 128bit memory interface
  • PCIe 5.0
  • WINDFORCE cooling system

Deployment does not remove the need to choose a lifecycle policy. A service that scales to zero can save money during idle periods but incurs a cold start when the first request arrives. A warm, continuously available process reduces that first-request delay while consuming resources between requests. Measure both behaviors with the model and concurrency you actually expect.

Serve inference over HTTP

For production request/response traffic, use a Modal Server or a web-server function. Servers are designed for low-latency HTTP handling, can use GPUs, can mount Volumes and Secrets, and can be clustered across multiple GPU nodes. The exact decorator and server configuration names vary with the installed SDK, so check the current API reference when translating the following pattern to your version.

import modal

app = modal.App("sentiment-api")
image = modal.Image.debian_slim().uv_pip_install("transformers[torch]", "fastapi")

@app.function(image=image, gpu="h100")
@modal.fastapi_endpoint(method="POST")
def predict(request: dict):
    # Load or reuse the model in the container's supported startup hook.
    # Validate request fields before invoking the model.
    text = request["text"]
    return {"result": run_model(text)}

Keep request validation, model invocation and response serialization separate. Reject malformed JSON, missing fields and inputs that exceed your model’s context or memory budget before they reach the GPU. Return a stable error shape so clients can distinguish validation failures, capacity failures and model errors.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use Secrets for credentials

Private model registries, databases and observability systems should receive credentials through Modal Secrets rather than literals in the image or source file. Mount the required Secret on the function or server using the SDK’s current configuration syntax. Rotate credentials independently of model code and ensure logs never print tokens or authorization headers.

Use a Volume for shared artifacts

Mounting a Volume lets multiple server instances read the same model files without rebuilding each image. Plan updates as an atomic release: upload a complete version to a new directory, validate it, then change the configuration to point to that version. Avoid overwriting files that a live process may be reading.

Deploy an MLflow model with the Modal plugin

If your model is already packaged as an MLflow artifact, the Modal deployment plugin can automate much of the serving setup. Its workflow extracts model artifacts and dependencies, uploads the files to a Modal Volume, generates FastAPI endpoints, builds the container, deploys it and returns an HTTPS endpoint.

  1. Install and configure the MLflow and Modal tooling in the environment used for deployment.
  2. Point the plugin at the MLflow model artifact and its dependency specification.
  3. Let the plugin place artifacts in the selected Modal Volume rather than downloading them separately in every request.
  4. Review the generated image and endpoint configuration, especially the Python and framework versions.
  5. Deploy and test the returned HTTPS URL with a representative payload.

The generated interface includes /invocations and /predict_stream FastAPI endpoints. Confirm which endpoint your client should call, the expected MLflow input schema and whether streaming is appropriate for your model. The plugin reduces boilerplate, but it does not decide whether the chosen GPU has enough memory or whether your preprocessing code is safe for concurrent requests.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Choose a GPU and serving architecture

Do not select an accelerator solely by name. Evaluate the complete workload: model weights, tokenizer, runtime allocations, attention or KV cache, batch size and the concurrency you need.

Rank #4
Sale
GIGABYTE Radeon RX 9070 XT Gaming OC 16G Graphics Card, PCIe 5.0, 16GB GDDR6, GV-R9070XTGAMING OC-16GD Video Card
  • Powered by Radeon RX 9070 XT
  • WINDFORCE Cooling System
  • Hawk Fan
  • Server-grade Thermal Conductive Gel
  • RGB Lighting
Decision axis Question to answer What to measure
Model memory fit Does the checkpoint and runtime fit without paging or allocation failures? Peak GPU memory during initialization and the longest realistic request.
Latency How quickly must a single interactive request complete? Cold-start time separately from warm-request time; report p50 and tail latency.
Throughput How many requests or generated tokens must the service process? Requests per second or tokens per second at the target batch and concurrency.
Scaling behavior Is traffic bursty, steady or continuously high? Scale-from-zero delay, queue depth and behavior when several containers start together.
Operational complexity How much infrastructure should your team manage? Container, autoscaling, rollout and GPU-host operations delegated to Modal versus self-managed infrastructure.
Cost What does the workload consume while active? GPU, CPU and memory seconds, including startup and idle-warm time.

Modal notebook documentation describes configurations with up to eight A100s or H100s. That limit and the set of available GPU types are current capabilities, not a promise that every region or account can obtain them at any moment. Multi-GPU configurations are useful when a model cannot fit on one device or when parallelism improves throughput, but they add communication and placement complexity.

Functions versus Servers

Use a regular GPU function for batch jobs, experiments, asynchronous work or traffic that can tolerate startup. Use a Server when clients need an HTTP contract and predictable handling of concurrent requests. A clustered Server is the appropriate direction when one process or one GPU cannot provide the memory or throughput required, provided your model supports the needed parallelism.

Understand cost without relying on stale numbers

Modal’s billing is usage-based: active CPU, memory and GPU time are the important drivers. A scale-to-zero function generally avoids GPU charges while no container is running, whereas a warm service continues consuming resources between requests. Image builds, weight downloads and failed initializations can also affect how much time a deployment spends in active infrastructure.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Exact GPU prices and availability are volatile. Check Modal’s current pricing page immediately before committing to a capacity plan, and record the region, GPU type, memory allocation and date of any estimate. A benchmark on one accelerator is not a price quote for a different model, batch size or traffic pattern.

Cold starts, batching and concurrency

Cold-start latency includes image retrieval, dependency import, weight access and model initialization. Reduce it by keeping images focused, placing large artifacts in a fast shared Volume when appropriate, and avoiding repeated model construction per request. The correct lifecycle hook depends on the SDK version; verify that initialization occurs once per warm container rather than once per invocation.

Batching can improve throughput but may increase the latency of the first item in a batch. Set a maximum batch size and a maximum wait window, then measure tail latency under the expected arrival rate. For generative models, concurrency also increases KV-cache memory, so a configuration that succeeds for one request may fail under parallel load.

Benchmark at least these cases:

  • First request after scaling from zero.
  • Warm single-request latency.
  • Target concurrent requests with realistic input and output lengths.
  • Long-running load until autoscaling has stabilized.
  • Deployment and model-update time, including artifact transfer.

Modal has published a TensorRT-LLM example exceeding 25,000 output tokens per second on a single NVIDIA H100. That is a configuration-specific example, not a universal performance promise; the model, engine, batching and measurement method determine whether your result is comparable.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Troubleshoot common deployment failures

Package or import errors

If a module imports locally but not remotely, it is missing from the Modal image. Add it to the image’s dependency installation, rebuild and run the file again. Check that the package name used by the installer matches the import name and that optional framework extras, such as the PyTorch extra for Transformers, are included.

Best Value
Sale
ASUS Prime Radeon RX 9070 XT 16GB GDDR6 OC Edition Gaming Graphics Card | PCIe 5.0, HDMI/DP 2.1, 2.5-slot, Axial-tech Fans, Dual-ball Fan Bearings, dual BIOS, ASUS GPU Guard
  • Axial-tech fans now feature a smaller fan hub that facilitates longer blades and a barrier ring that increases downward air pressure
  • Phase-change GPU thermal pad helps ensure optimal heat transfer, lowering GPU temperatures for enhanced performance and reliability
  • 2.5-slot design allows for greater build compatibility while maintaining cooling performance
  • Dual-ball fan bearings last up to twice as long as standard conventional sleeve bearings designs
  • 0dB technology lets you enjoy light gaming in relative silence

CUDA or device errors

Verify that the function has a GPU decorator, the framework build is compatible with the image’s CUDA runtime and the model is explicitly placed on CUDA. Keep initialization inside the remote GPU function or its startup hook. A CPU-only local test cannot prove that the remote CUDA stack is correct.

Out-of-memory errors

Measure peak memory during model load and inference, not just the checkpoint size. Lower batch size, shorten input or output limits, use a smaller or quantized model when supported, or select a GPU with more memory. If the model still cannot fit, consider a multi-GPU Server and confirm that the model framework supports its parallelism strategy.

Every request downloads the model

This usually means weights are initialized inside the request path without a persistent cache or Volume. Move initialization to the container startup lifecycle, mount a durable artifact location, and verify that the process reuses the loaded object for warm requests.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The deployed URL works but clients receive errors

Check the HTTP method, JSON shape and route name first. For MLflow deployments, verify whether the client is calling /invocations or /predict_stream and whether its payload matches the generated schema. Inspect server logs for validation failures separately from model exceptions, and return structured status codes rather than exposing raw stack traces.

Deployment cannot obtain the requested GPU

GPU capacity and availability can vary by region and time. Try an alternative supported GPU that still satisfies the memory and latency requirements, or change the scaling plan. Do not silently fall back to CPU if the model’s service-level objective requires GPU inference.

Security and production operations checklist

  • Keep registry, database and API credentials in Secrets, never in source or image layers.
  • Authenticate HTTP requests and apply rate limits before expensive generation work.
  • Log request identifiers, latency, status and model version; redact prompts, tokens and personal data as required by your policy.
  • Version model artifacts and image dependencies so a rollback can restore both code and weights.
  • Set input-size and output-size limits to prevent accidental or abusive GPU exhaustion.
  • Test deployment from a clean client, not only from the developer’s authenticated shell.
  • Monitor cold starts, warm latency, GPU utilization, memory headroom, queue depth and error rate.

End-to-end deployment checklist

  1. Install the SDK with pip install modal and authenticate using modal setup.
  2. Define a modal.App and an image containing every runtime dependency.
  3. Attach a GPU in the function or Server declaration.
  4. Load the model remotely, place it on CUDA and verify one representative prediction.
  5. Choose a weight strategy: startup download, image-baked artifact or Modal Volume.
  6. Run the file with modal run your_file.py and test failure cases.
  7. Select a Server or web-server function when callers need HTTP.
  8. Deploy with modal deploy your_file.py, then test the reported URL and Swagger documentation where available.
  9. Measure cold and warm latency, throughput, concurrency, memory and active-resource cost.
  10. For MLflow, verify the generated Volume, image, endpoint paths and input schema before handing the URL to clients.

Frequently Asked Questions

What is the difference between modal run and modal deploy?

modal run invokes the application for development and validation. modal deploy registers a persistent application that can expose HTTP endpoints for ongoing use.

Can a Modal Server use more than one GPU?

Yes. Modal’s Server model supports GPU-backed deployments and can be clustered across multiple GPU nodes. The model framework must support the parallelism approach you choose.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

How should I store large model weights?

Use a Modal Volume when you want artifacts separate from the image and readable by multiple server instances. Ensure the files are complete and versioned before switching live processes to a new release.

Quick Recap

Bestseller No. 1
ASUS Dual Radeon RX 9060 XT 16GB GDDR6 Gaming Graphics Card | PCIe 5.0, HDMI 2.1b, DisplayPort 2.1a, 2.5-slot design, Axial-tech Fans, 0dB Technology
ASUS Dual Radeon RX 9060 XT 16GB GDDR6 Gaming Graphics Card | PCIe 5.0, HDMI 2.1b, DisplayPort 2.1a, 2.5-slot design, Axial-tech Fans, 0dB Technology
0dB technology lets you enjoy light gaming in relative silence; Dual BIOS switch lets you toggle between Quiet and Performance BIOS profiles
$529.00
Bestseller No. 2
GIGABYTE GeForce RTX 5070 Ti Gaming OC 16G Graphics Card, 16GB 256-bit GDDR7, PCIe 5.0, WINDFORCE Cooling System, GV-N507TGAMING OC-16GD Video Card
GIGABYTE GeForce RTX 5070 Ti Gaming OC 16G Graphics Card, 16GB 256-bit GDDR7, PCIe 5.0, WINDFORCE Cooling System, GV-N507TGAMING OC-16GD Video Card
Powered by the NVIDIA Blackwell architecture and DLSS 4; Powered by GeForce RTX 5070 Ti; Integrated with 16GB GDDR7 256bit memory interface
$1,249.99
Bestseller No. 3
GIGABYTE GeForce RTX 5060 WINDFORCE OC 8G Graphics Card, Cooling System, 8GB 128-bit GDDR7, PCIe 5.0, Manufactured by NVIDIA, DisplayPort & HDMI - Video Output Interface, GV-N5060WF2OC-8GD Video Card
GIGABYTE GeForce RTX 5060 WINDFORCE OC 8G Graphics Card, Cooling System, 8GB 128-bit GDDR7, PCIe 5.0, Manufactured by NVIDIA, DisplayPort & HDMI - Video Output Interface, GV-N5060WF2OC-8GD Video Card
Powered by the NVIDIA Blackwell architecture and DLSS 4; Powered by GeForce RTX 5060; Integrated with 8GB GDDR7 128bit memory interface
$495.99
SaleBestseller No. 4
GIGABYTE Radeon RX 9070 XT Gaming OC 16G Graphics Card, PCIe 5.0, 16GB GDDR6, GV-R9070XTGAMING OC-16GD Video Card
GIGABYTE Radeon RX 9070 XT Gaming OC 16G Graphics Card, PCIe 5.0, 16GB GDDR6, GV-R9070XTGAMING OC-16GD Video Card
Powered by Radeon RX 9070 XT; WINDFORCE Cooling System; Hawk Fan; Server-grade Thermal Conductive Gel
$814.99
SaleBestseller No. 5
ASUS Prime Radeon RX 9070 XT 16GB GDDR6 OC Edition Gaming Graphics Card | PCIe 5.0, HDMI/DP 2.1, 2.5-slot, Axial-tech Fans, Dual-ball Fan Bearings, dual BIOS, ASUS GPU Guard
ASUS Prime Radeon RX 9070 XT 16GB GDDR6 OC Edition Gaming Graphics Card | PCIe 5.0, HDMI/DP 2.1, 2.5-slot, Axial-tech Fans, Dual-ball Fan Bearings, dual BIOS, ASUS GPU Guard
0dB technology lets you enjoy light gaming in relative silence; Dual BIOS switch lets you toggle between Quiet and Performance BIOS profiles
$831.99

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.