Skip to main content

Deploying AI Models

Deploy open-source models from Hugging Face on your own infrastructure with full control over scaling, costs, and data privacy. Every deployment belongs to an organization and is isolated from other organizations.

Environment​

Self-hosted models use one of several inference engines depending on the model type:

  • vLLM (113 models) -- High-performance inference with PagedAttention, continuous batching, and OpenAI-compatible API. Used for LLMs, multimodal, and embedding models.
  • Transformers (24 models) -- Custom Python servers using HuggingFace Transformers directly. Used for models not yet supported by vLLM.
  • TTS Engine (16 models) -- Custom text-to-speech servers exposing /v1/audio/speech.
  • Whisper Engine (5 models) -- Whisper-compatible STT servers exposing /v1/audio/transcriptions.
  • Video Engine (6 models) -- Video generation servers exposing /v1/video/generations.
  • Custom (5 models) -- Generic custom servers with configurable endpoints.

See Self-Hosted Models for the full engine architecture, provider routing, and model catalogue.

Organization Scoping​

Every model deployment belongs to your organization:

  • It runs in your organization, isolated from other organizations
  • It is billed to your organization and checked against its budgets
  • Governance requirements that apply to models must be met before it deploys

Deployment Options​

Choose when your model runs in the deploy form's Scheduling step (or with the deploy fields over REST):

Always On​

Behavior: The model runs 24/7 with the number of Replicas you set.

  • Use Case: Production applications with consistent traffic
  • Cost: Fixed compute costs regardless of usage
  • Latency: Instant response (no cold start)
  • Variable load: turn on Autoscaling to scale between a minimum and maximum on CPU and memory
Best for Production

Always On deployment ensures instant response times and is ideal for production applications with consistent traffic patterns.

On Demand (Auto-Shutdown)​

Behavior: The model scales to zero after it has been idle for Auto-shutdown after (minutes), and wakes on the next request.

  • Use Case: Development, testing, low-traffic applications, models used only inside workflow runs
  • Cost: Pay only while the model is awake
  • Latency: The first request after idle waits while the model starts
  • No capacity: if the cloud has no machine of the model's instance type to give (for example no GPU of its type, spot or on-demand) for 20 minutes, the wake is given up: every request waiting on it fails with the reason (503, model_capacity_unavailable) and a workflow calling the model fails and stops. The next request tries again.
  • Configuration: an idle window of at least 1 minute is required (auto_shutdown_minutes over REST); the form refuses 0
  • Stopping: an idle model, like a running one, has Stop on its page and in the Self Hosted AI list. A stopped model does not wake on requests until it is started again.
Cost Optimization

On Demand deployment can significantly reduce costs for intermittent workloads by stopping the model during idle periods.

Demand scaling (On Demand + Auto-scaling)​

An on-demand model can also scale with its traffic while it is awake. Choose Auto-scaling and set:

SettingREST fieldMeaning
Min replicasmin_replicasFewest replicas while awake (at least 1)
Max replicasmax_replicasMost replicas (at least Min replicas)
Target concurrencytarget_concurrencyRequests in flight one replica handles before another is added

While awake, the model adds replicas as soon as load rises and removes them only after load stays low, so it does not flap. When idle for the auto-shutdown window it still scales to zero. All three settings are required, and the scaling mode is exactly Fixed (fixed, always wake to Replicas) or Auto (auto); any other value is refused. Auto-scaling is only for on-demand models; always-on models use Autoscaling.

Scheduled​

Behavior: The model starts and stops at the times you set and runs Replicas pods in between.

  • Use Case: Batch processing, business hours only, regional availability
  • Cost: Only charged while the schedule has it running
  • Latency: Instant during scheduled hours, unavailable outside them
  • Configuration: pick the days, a start time and a stop time, and a timezone. A schedule needs at least one start and one stop. Over REST, send schedule_rules (see POST /api/v1/ai-gateway/models/:id/deploy).

Resource Configuration​

Choose the right hardware for your model size:

Model SizeGPUVRAMRecommended For
Small (7B parameters)1x V100 / A10G16-24GBLlama-2-7B, Mistral-7B
Medium (13B parameters)1x A10G24GBLlama-2-13B, Vicuna-13B
Large (70B parameters)4x A100 (40GB)160GB totalLlama-2-70B with tensor parallelism
Quantized (4-bit)1x V1008-12GB70B models quantized to 4-bit

Available Instance Types​

These machine types are available:

GPU Instances:

InstanceGPUGPU MemoryvCPUsRAM
g5.xlarge1x A10G24GB416GB
g5.2xlarge1x A10G24GB832GB
g5.12xlarge4x A10G96GB48192GB
p3.2xlarge1x V10016GB861GB
p3.8xlarge4x V10064GB32244GB

CPU-Only Instances:

InstancevCPUsRAM
c5.2xlarge816GB
c5.4xlarge1632GB

What a deployment costs is the infrastructure it runs on, shown in FinOps.

Capacity Options​

Spot Instances​

Self-hosted models can opt into AWS Spot capacity -- the same option available for AutoML and fine-tuning jobs.

UI: in the deploy form (Resources step), toggle Use Spot Instances. When enabled, the Fall back to on-demand when spot capacity is unavailable checkbox (recommended, checked by default) controls the behaviour:

  • Checked (default): spot is requested as a scheduling preference: the model runs on a spot node when one has room or a new node is added for it, and on on-demand capacity otherwise. Availability is never sacrificed for price.
  • Unchecked (strict spot): the deployment pins to spot and waits until spot capacity is available.

Change it later: on the model's Settings tab, Edit Configuration shows the same spot setting. Saving a change moves the running model on or off spot: it restarts on the new capacity, as it does at a new size, and is not redeployed. Capacity in the read-only view shows the current choice.

REST: pass useSpot / spotFallback in the deploy body, and in PATCH /api/v1/ai-gateway/models/:id/resources to change a deployed model -- see AI Models API and Spot Instance Support. A fine-tuned model takes the same option in the Deploy Fine-Tuned Model dialog (useSpot / spotFallback on POST /api/v1/ai-gateway/fine-tuning-jobs/:id/deploy).

If a Spot Instance is taken back, your model gets a 2-minute warning and moves to a replacement machine. A request the gateway had not sent to the model yet answers 503 and the caller sends it again. A request the model was still answering fails with an error that opens Response lost: and is never sent again, by the gateway or a workflow node, since the model may already have done the work. Interruption never produces partial results.

Scale-to-Zero (On-Demand Mode)​

Set Auto-shutdown (or auto_shutdown_minutes via REST) to scale the model to zero replicas after N idle minutes. The first request after idle wakes the model back to its configured replica count. For scheduled batch workloads a short timeout (e.g. 10 minutes) trims the idle GPU tail without affecting the run -- model pods are continuously busy while a workflow is active.

Model Operations​

Start and Stop​

Start and stop a deployed model from its details page without deleting it. Stopping frees its compute and keeps its configuration; starting brings it back with the same settings (and is checked against its budget).

Delete​

Delete on a model's details page removes it, with its build, its deployment and its images; it is refused while an app, workspace, job, router, workflow or agent uses the model. While a model is still building or deploying, Delete is the only action on its page and it is the cancel: the image build stops at once, nothing is deployed afterwards, and the model leaves every list and stops costing anything. Over REST: DELETE /api/v1/ai-gateway/models/:id.

Changing a Deployed Model​

Edit a running model on its Settings tab and click Save. The model is changed in place; it is never deleted or redeployed, and its endpoint stays the same:

  • CPU, memory, disk and GPU: the model restarts at exactly the new size. A bigger size is checked against the model's budget first; if the budget refuses it, nothing changes.

Sizes are shown and typed as on every workload's page: CPU in vCPU, memory and disk in GB (1 GB = 1024 MB). The deploy form and the Settings tab take CPU (vCPU) and Memory (GB) as numbers; the model is stored and deployed at the Kubernetes quantity of the same amount (2 vCPU is 2000m, 8 GB is 8Gi), which is also what the REST API and the Python SDK take and return.

  • Replicas, scheduling and scaling: take effect on the running model without a restart. The combination must be valid (an on-demand model keeps an idle window; auto-scaling keeps its three settings), or Save shows why and nothing changes.

Over REST: PATCH /api/v1/ai-gateway/models/:id/resources resizes, and PATCH /api/v1/ai-gateway/models/:id changes replicas, scheduling and scaling. See AI Models API.

Status and Logs​

The details page shows the model's status, replicas and resource use, and its Logs tab shows the image build, deployment events and runtime logs. Over REST: GET /api/v1/ai-gateway/models/:id/status and GET /api/v1/ai-gateway/models/:id/logs.

Customizing Dockerfile​

For advanced use cases, customize the Docker image for your model deployment. The platform provides Dockerfile templates as starting points:

# Example: Custom vLLM Dockerfile (based on platform template)
FROM nvcr.io/nvidia/pytorch:23.10-py3

# Install vLLM and dependencies
RUN pip install vllm transformers accelerate

# Set environment variables
ENV MODEL_NAME=mistralai/Mistral-7B-Instruct-v0.2
ENV PORT=8000
ENV GPU_MEMORY_UTILIZATION=0.95
ENV MAX_MODEL_LEN=8192

# Create model directory
RUN mkdir -p /models
WORKDIR /models

# Expose port
EXPOSE 8000

# Health check endpoint
HEALTHCHECK CMD curl -f http://localhost:8000/health || exit 1

# Start vLLM server
CMD python -m vllm.entrypoints.openai.api_server \
--model $MODEL_NAME \
--port $PORT \
--gpu-memory-utilization $GPU_MEMORY_UTILIZATION \
--max-model-len $MAX_MODEL_LEN \
--trust-remote-code

Dockerfile Templates​

The deploy form starts from the platform's pre-built model templates (over REST: GET /api/v1/ai-gateway/models/prebuilt), for example Mistral 7B and Llama models on vLLM, and custom vLLM models.

Every template offered has a certified environment: the instance, CPU, memory, disk and GPU it was certified on, and for a chat model its context window and max output tokens. A vLLM model's context window is its Dockerfile's --max-model-len, and its max output tokens default to a quarter of it, so a reply leaves room for the prompt (Mistral 7B: 32,768 and 8,192); its owner may raise max output up to the whole context window. A model served another way (Transformers) has the limits its vendor publishes. The model records them when it is created, so nothing is entered by hand, and a deploy, restart or upgrade never changes them.

A vLLM model records its served context window and a quarter of it as its max output tokens, leaving room for the prompt (Mistral 7B: 32768 and 8192). To change the max output, open the model's Settings tab, choose Edit Configuration and enter Max Output Tokens: the field shows the most it may be (Up to 32,768 tokens per reply., the whole context window for a vLLM model). The context window is the one the model serves and is not changed by hand. Over REST, send maxOutputTokens in PATCH /api/v1/ai-gateway/models/:id; GET /api/v1/ai-gateway/models/:id gives the most it may be as maxOutputCeiling.

Common customizations:

  • Additional Python packages
  • Custom tokenizers
  • Preprocessing scripts
  • Model quantization
  • Multi-GPU configuration

Deployment API Endpoints​

EndpointMethodDescription
/api/v1/ai-gateway/models/prebuiltGETPre-built models you can deploy
/api/v1/ai-gateway/modelsPOSTRegister a self-hosted model
/api/v1/ai-gateway/models/:id/deployPOSTDeploy it (scheduling, scaling, instance, spot)
/api/v1/ai-gateway/models/:idPUTChange replicas, scheduling and scaling in place
/api/v1/ai-gateway/models/:id/resourcesPATCHResize CPU, memory, disk, GPU in place
/api/v1/ai-gateway/models/:id/startPOSTStart a stopped model
/api/v1/ai-gateway/models/:id/stopPOSTStop a running model (keeps its configuration)
/api/v1/ai-gateway/models/:id/statusGETDeployment status
/api/v1/ai-gateway/models/:id/logsGETBuild, deployment and runtime logs

Full reference: AI Models API.

Next Steps​