IMPORTANT: To view this page as Markdown, append `.md` to the URL (e.g. /get-started.md). For the complete documentation index, see llms.txt.
Skip to main content
For the complete documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /get-started.md).

Environment variables

This page documents all environment variables you can use to configure MAX behavior. These variables control server settings, logging, telemetry, performance, and integrations.

How to set environment variables

You can set environment variables in several ways:

# Export in your shell
export MAX_SERVE_HOST="0.0.0.0"

# Pass to Docker container
docker run --env "MAX_SERVE_HOST=0.0.0.0" modular/max-nvidia-full:latest ...

# Use a .env file in your working directory
echo "MAX_SERVE_HOST=0.0.0.0" >> .env

Configuration precedence

When you configure the same setting in multiple places, the following precedence applies (highest to lowest):

  1. CLI flags or direct Python initialization: For example, --port 8080 or Settings(MAX_SERVE_PORT=8080). CLI flags pass directly to the Settings constructor, so they have the same precedence as direct Python initialization.
  2. Environment variables: export MAX_SERVE_HOST="0.0.0.0"
  3. .env file values: Values defined in a .env file in your working directory

Serving

These variables configure the MAX model serving behavior.

For more information on serving a model with MAX, explore the text to text and image and video to text guides.

VariableDescriptionValuesDefault
MAX_SERVE_HOSTHostname for the MAX serverString0.0.0.0
MAX_SERVE_PORTPort for serving MAXInteger8000
MAX_SERVE_METRICS_ENDPOINT_PORTPort for the Prometheus metrics endpointInteger8001
MAX_SERVE_ALLOWED_IMAGE_ROOTSAllowed root directories for file:// URI access, as a JSON array (for example, '["/srv/images"]')JSON array stringEmpty
MAX_SERVE_MAX_LOCAL_IMAGE_BYTESMaximum size in bytes for local image filesInteger20971520 (20 MiB)
MAX_SERVE_MAX_REQUEST_BYTESMaximum size in bytes of an accepted HTTP request body. MAX rejects a larger request with HTTP 413, based on the declared Content-Length or on the bytes counted as the body streams in. Raise it for requests that inline large base64 media, or set to 0 to disable the limit.Integer (≥ 0)104857600 (100 MiB)
MAX_SERVE_MAX_BYTESServer-level maximum size in bytes for media resolved from http(s):// or data: URIs. MAX applies it on top of any per-model cap, and the smaller of the two wins. Set to 0 to disable the server-level cap.Integer0
MAX_SERVE_MEDIA_KINDDefault media kind used in size-limit error messages when a resolver caller doesn't specify oneimage, videoimage
MAX_SERVE_MEDIA_URL_ALLOWED_HOSTSAllowlist of otherwise-blocked internal hosts that MAX can fetch media from while SSRF protection stays on. Each entry is an exact hostname (case-insensitive) or an IP address or CIDR range, such as '["minio.internal", "10.0.0.0/8"]'JSON array stringEmpty
MAX_SERVE_MEDIA_URL_SSRF_PROTECTION_ENABLEDProtects against server-side request forgery (SSRF) when MAX fetches media from a client-supplied http(s):// URL. MAX checks the host at each redirect and rejects any host that resolves to a private, loopback, or otherwise non-public address. Turn this off only as a last resort, to restore the earlier unchecked behavior. To allow specific internal hosts while the protection stays on, use MAX_SERVE_MEDIA_URL_ALLOWED_HOSTS.true, falsetrue
MAX_SERVE_API_TYPESConfigures which API types MAX serve exposes. Accepts a JSON array of API type strings (for example, '["responses"]'). Use this to enable the Responses API for tasks like image generation.JSON array stringNone
MAX_SERVE_GRACEFUL_SHUTDOWN_TIMEOUT_SSeconds to wait for in-flight requests to finish after SIGTERM before canceling them and exitingInteger5
MAX_SERVE_MAX_QUEUE_SIZECap on the request queue to the model worker. Once full, the server rejects new requests with HTTP 429 instead of enqueuing them. Pair with MAX_SERVE_MAX_PENDING_REQUESTS for effective backpressureIntegerNone (unbounded)
MAX_SERVE_MAX_PENDING_REQUESTSCap on the scheduler's pending prefill queue depth. When set, the model worker stops pulling new requests from the request queue once it holds this many not-yet-running requestsInteger (≥ 1)None (unbounded)
MAX_SERVE_STREAM_MIN_CHUNK_TOKENSMinimum number of tokens per streamed server-sent events (SSE) chunk. Larger values coalesce streaming output into bigger chunks without affecting time to first tokenInteger1
MODULAR_DKV_TENANT_IDTenant identity for the dKV external KV cache tier. Required when using the dKV connectorStringNone
MODULAR_DKV_DISABLE_G0_TOUCHDisable recency refresh (touch) of an external KV cache tier when the on-GPU cache serves a request's prefix0, 10
MAX_SERVE_BATCH_PRIORITYBatch scheduling strategy that controls how replicas prioritize prefill (context encoding) versus decode (token generation) requestsprefill_first, decode_first, balanced, per_replicaper_replica

Logging

These variables control logging behavior and verbosity.

You can read more about logs when using the MAX container.

VariableDescriptionValuesDefault
MAX_SERVE_LOGS_CONSOLE_LEVELConsole log verbosity levelCRITICAL, ERROR, WARNING, INFO, DEBUGINFO
MODULAR_STRUCTURED_LOGGINGEnable JSON-formatted structured logging for deployed services0, 11
MAX_SERVE_LOGS_FILE_PATHPath to write log filesFile pathNone
MAX_SERVE_LOG_PREFIXPrefix to prepend to all log messagesStringNone

Telemetry and metrics

These variables control telemetry collection and metrics reporting.

For more information, read about telemetry.

VariableDescriptionValuesDefault
MAX_SERVE_DISABLE_TELEMETRYDisable remote telemetry collection0, 10
MODULAR_USER_IDUser identifier for telemetry (for example, your company name)StringNone
MAX_SERVE_DEPLOYMENT_IDDeployment identifier for telemetry (for example, your application name)StringNone
MAX_SERVE_OTLP_METRICS_ENDPOINTPush a self-calibrating exponential-histogram shadow (<metric>.exponential) of every histogram metric to an OTLP endpoint, alongside the Prometheus /metrics histogramsEndpoint URLNone
MAX_SERVE_EPLB_PROFILEEnable expert-parallel load balancing (EPLB) statistics profiling in max serve0, 10

Debugging

The MODULAR_DEBUG environment variable enables one or more MAX debugging options. Set it to a comma-separated list of option names, using name=value for options that take a value:

export MODULAR_DEBUG=nan-check,assert-level=all

This table includes all options you can add to MODULAR_DEBUG:

OptionDescriptionTypeAccepted valuesDefault
sensibleEnable a curated default debugging setBooleanN/Afalse
nan-checkInsert NaN/Inf checks on a sampled subset of floating-point kernel outputs (see nan-check-stride)BooleanN/Afalse
nan-check-strideWhen nan-check is enabled, check one of every N floating-point kernel outputs. Set to 1 for full coverageIntegerPositive integer (≥1)20
uninitialized-read-checkDetect reads of uninitialized memoryBooleanN/Afalse
device-sync-modeForce synchronous GPU execution for debuggingBooleanN/Afalse
stack-trace-on-errorShow Mojo stack traces on runtime errorsBooleanN/Afalse
stack-trace-on-crashShow Mojo stack traces on crashesBooleanN/Afalse
source-tracebacksInclude Python source locations in error messagesBooleanN/Afalse
op-log-levelLog level for op-level execution tracingStringtrace, debug, info, warning, error, criticaloff
assert-levelAssertion level for the Mojo standard libraryStringnone, warn, safe, allnone
print-styleOutput format for tensor debug printingStringcompact, full, binary, binary_max_checkpointcompact
ir-output-dirDirectory where MAX dumps intermediate compiler IRPathFilesystem pathunset

The following variables control memory-allocation debugging:

VariableDescriptionValuesDefault
MODULAR_DEBUG_DEVICE_ALLOCATORComma-separated allocator debugging modes. poison-all fills every memory-manager allocation with a NaN-pattern byte; the uninitialized-read-check debug option automatically enables uninitialized-poisonComma-separated modesNone
MODULAR_DEVICE_CONTEXT_MEMORY_MANAGER_POISON_PATTERNByte pattern written by the poison-all allocator modeByte (0–255)Built-in NaN pattern

The following variable overrides the GPU compiler MAX uses:

VariableDescriptionValuesDefault
MODULAR_NVPTX_COMPILER_PATHPath to a custom NVIDIA ptxas binary, useful as an escape hatch when the installed NVIDIA driver is too old for the bundled compilerPathUnset

Profiling

For GPU profiling details, see GPU profiling with Nsight Systems.

The following variable controls runtime profiling and tracing.

VariableDescriptionValuesDefault
MODULAR_ENABLE_PROFILINGEnable runtime profiling and tracingoff, on, detailedoff

Performance and caching

The following variables configure caching and memory behavior.

VariableDescriptionValuesDefault
MODULAR_MAX_CACHE_DIRDirectory to save MAX model cache for reusePath$MODULAR_CACHE_DIR/.max_cache
MODULAR_CACHE_DIRConfigure cache directory for all MAX filesystemsPathSee note below
MODULAR_MAX_SHM_WATERMARKPercentage of /dev/shm to allocate for shared memory. Set to 0.0 to disable shared memory.Float (0.0–1.0)0.9
MAX_EAGER_OP_PRECOMPILEControls how the eager interpreter compiles its built-in op targets. The default compiles each target lazily on its first dispatch, which avoids a long cold-cache compile when a program touches only a few targets. Set to 1 to precompile the full (device, dtype) matrix at import so steady-state dispatch never recompiles. MAX reads the value when the sweep runs rather than at import.0, 10
MAX_EAGER_EXECUTORSelect the eager execution backendcomposite, jit, interpreter, compilecomposite
MAX_EAGER_ALLOW_LAZY_COMPILEAllow max serve to compile eager interpreter models on demand instead of requiring a warm cache from max warm-interpreter-cache0, 10
MODULAR_DEVICE_CONTEXT_MEMORY_MANAGER_VMMToggle the VMM defragmenting allocator, which avoids external-fragmentation OOMs. Enabled by default on NVIDIA GPUs; opt in on AMD MI300-series GPUs with 10, 11 (NVIDIA), 0 (AMD)
MODULAR_ENABLE_APPLE_NAIVE_FA_DECODESet to 0 to opt out of the split-K decode attention kernel on Apple GPUs (paged KV cache MHA and GQA decode)0, 11
MODULAR_MAX_RELEASE_FREE_HOST_MEMORYReturn freed host memory to the operating system after model loading completesAny non-empty valueUnset (disabled)

Weight loading

The following variables control how MAX handles model weights when loading from a checkpoint.

VariableDescriptionValuesDefault
MODULAR_AUTO_CAST_WEIGHTSAuto-cast loaded weights between float32 and bfloat16 when checkpoint and module dtypes mismatch (shape must match). Other dtype mismatches still raise.true, falsetrue
APPLE_FLUX2_INT8_W8A8On Apple M5 GPUs, controls int8 W8A8 quantization for FLUX.2 checkpoints: FLUX.2-klein bf16 checkpoints default to int8 W8A8 (set 0 to opt out); NVFP4 checkpoints opt into an int8 W8A8 requant at load with 1.0, 11 (FLUX.2-klein bf16)
MODULAR_MAX_RELEASE_HOST_WEIGHTSSet to 1 to release the host copies of model weights once the model is loaded on GPU, reducing host memory usage. GPU deployments only1Unset (disabled)

Hugging Face

Configure your Hugging Face integration with the following environment variable:

VariableDescriptionValuesDefault
HF_TOKENHugging Face authentication token for accessing gated modelsStringNone

Was this page helpful?