Environment variables

The complete AFM runtime environment contract.

This is the source-audited list of variables read or populated by the shipped afm process, including its applied MLX and DwarfStar patches. The 91 names are grouped by who should touch them—not alphabetically—so production controls do not get confused with benchmark switches.

How values are read

Boolean parsing is not uniform. Some older paths require exactly 1; newer paths may also accept true, while “enabled by default” controls are usually disabled by 0, false, or off. Use the accepted values in each row rather than assuming every truthy string works.

# Persist for this shell and child processes
export AFM_DEBUG=1
afm mlx -m mlx-community/Qwen3-0.6B-4bit

# Apply to one process only
AFM_CLEAR_GPU_CACHE=1 afm mlx -m <model>

Operator configuration

These are the variables an operator is most likely to use. Prefer a typed CLI option when the description names one: it is validated, appears in afm mlx --help-json, and makes process configuration easier to reproduce.

VariableValues · defaultEffect
MACAFM_MLX_MODEL_CACHEpath; unsetAdds a read-only root for curated or side-loaded checkpoints. AFM checks flat org/model, models/org/model, and Hugging Face cache layouts below it. It does not redirect downloads in the current build.
HUGGINGFACE_HUB_CACHEpath; unsetAdds an explicit Hugging Face Hub cache root to model discovery. Checked before HF_HUB_CACHE.
HF_HUB_CACHEpath; unsetAdds the standard Hugging Face Hub cache root to model discovery.
HF_HOMEpath; unsetUses <path>/hub as a Hugging Face model-cache candidate.
XDG_CACHE_HOMEpath; unsetUses <path>/huggingface/hub as a Hugging Face model-cache candidate.
MACAFM_MLX_METALLIBfile path; unsetOverrides the default.metallib selected for MLX. The path must point to a readable Metal library compatible with the build.
MACAFM_CACHE_PROFILE_PATHJSONL file path; unsetWrites prefix-cache timing records. An explicit --cache-profile-path wins; this name wins over the legacy AFM_CACHE_PROFILE_PATH alias.
AFM_CACHE_PROFILE_PATHJSONL file path; unsetLegacy alias for MACAFM_CACHE_PROFILE_PATH, used only when neither the CLI option nor the preferred variable is present.
AFM_DEBUG1; offEnables verbose AFM and patched MLX diagnostic logging, including request, scheduler, cache, and selected model-path details.
AFM_CLEAR_GPU_CACHE1; offClears MLX's GPU cache after each request. It can reduce retained-memory pressure, but usually costs throughput and should be used as a mitigation, not a default.
AFM_DSPARK1, true, on, or yes; offEnables DSpark behavior through the environment fallback. Prefer the typed --dspark-support startup option when possible.
AFM_DSPARK_DRAFTinteger; runtime defaultOverrides the DSpark draft-token limit used by speculative generation. Prefer --dspark-draft-tokens for validated user configuration.
AFM_EAGLE3_BLOCKinteger; 2Overrides the EAGLE3 speculative block size. Intended for controlled tuning of an already configured EAGLE3 server.
MLX_MAX_OPS_PER_BUFFERpositive integer; MLX defaultOverrides MLX's maximum operations per Metal command buffer. If neither MLX scheduling variable is set, AFM supplies 200 for DeepSeek V4 on Ultra chips.
MLX_MAX_MB_PER_BUFFERpositive integer; MLX defaultOverrides MLX's command-buffer memory accounting limit in megabytes. AFM supplies 100000 for DeepSeek V4 on Ultra chips only when both scheduling variables are absent.

A correct external model-store setup

# AFM discovers curated checkpoints here, but does not write downloads here.
export MACAFM_MLX_MODEL_CACHE=/Volumes/Models/afm

# Hugging Face-compatible tools and AFM discovery share this download cache.
export HF_HUB_CACHE=/Volumes/Models/huggingface/hub

See Model storage for lookup order and supported layouts.

Diagnostics and tracing

These settings increase logging, force evaluation, write traces, or alter cache behavior. Enable them for a bounded investigation and remove them afterward.

VariableValues · defaultEffect
AFM_GPU_TRACE_OUTPUTfile path; /tmp/afm-metal.traceChanges the output path for --gpu-trace. A path supplied by the active capture flow takes precedence.
AFM_GPU_TRACE_TEMPLATEshader or unset; system traceSelects the custom Xcode Metal Shader Profile template when set to shader and the template is installed; otherwise AFM uses Metal System Trace.
AFM_GPU_TRACE_FINALIZE_GRACE_SECONDSinteger >= 5; 120Controls how long AFM allows Instruments to finalize a GPU trace before cleanup.
AFM_PREFIX_CACHE_TRACE_BOUNDARY1, true, or yes; offLogs prefix-cache boundary decisions for scheduler and serial generation diagnosis.
AFM_PREFIX_CACHE_ALLOW_UNSAFE_EXACT_REPLAYinteger suffix length; offEnables an experimental exact-replay shortcut for the requested suffix length. It is explicitly unsafe and must not be used for production correctness.
AFM_PERF1; offPrints per-token MLX generation timing, including model construction and token-conversion work.
AFM_EAGLE3_PROFILE1; offPrints EAGLE3 verify, draft, and acceptance timing for speculative-generation analysis.
AFM_DEBUG_PREFILL1; offPrints Gemma 4 batched-prefill and shared-KV diagnostics when a multi-token batch is present.
AFM_DWARFSTAR_METAL_SOURCE_ROOTdirectory path; auto-discoveredOverrides the directory containing DwarfStar Metal source files. AFM normally derives the individual DS4_METAL_* paths from this root.
AFM_DWARFSTAR_TRACE_PROMPT1; offPrints DwarfStar prompt roles and token details. Prompt content may be sensitive; do not enable it in shared logs.

DeepSeek V4 and benchmark controls

VariableValues · defaultEffect
DSV4_KV_MODEsliding, full, or tq; slidingSelects the DeepSeek V4 KV-cache diagnostic mode. sliding is the production hybrid cache; full uses a simple full cache; tq requires the caller's TurboQuant KV mode.
DSV4_POOL_QUANT0/false/off/no disables; enabledControls quantization of DeepSeek V4 pooled long-context cache storage.
AFM_MLX_KERNELSnative or ds4; set by CLIStable runtime bridge populated from --mlx-kernels. When AFM is launched through its CLI, the typed option is authoritative.
VMLX_DSV4_KERNELSnative or ds4; nativeLegacy fallback kernel selector used only when AFM_MLX_KERNELS is absent.
VMLX_DSV4_NATIVE_MXFP40/false disables; enabledControls the native specialized DeepSeek V4 MXFP4 path when the kernel engine is native.
VMLX_DSV4_NATIVE_MXFP80/false disables; enabledControls the native symmetric MXFP8 matrix-vector path.
VMLX_DSV4_ACTIVATION_QAT0/false disables; enabledControls the official E4M3 activation fake-quantization round trip before eligible MXFP matrix multiplies.
VMLX_DSV4_STAGED_MOE1/true enables; enabledControls the staged native MXFP4 mixture-of-experts path.
VMLX_DSV4_STAGED_SELECTOR1/true enables; disabledAdds the staged route-selection path; it requires staged MoE.
VMLX_DSV4_SHARED_Q8_STAGE1 enables; disabledEnables the staged shared symmetric-Q8 expert path when its geometry and selector prerequisites match.
VMLX_DSV4_COOPERATIVE_DOWN1/true enables; disabledEnables the cooperative native MXFP4 down-projection experiment.
VMLX_DSV4_HALF_MULTIPLY0, all, gate_up, or down; 0Selects reduced-precision multiply experiments for the routed gate/up path, down path, or both. 1 and true mean all.
VMLX_DSV4_MXFP4_ROWS_PER_SIMD1, 2, or 4; 2Sets the native MXFP4 rows handled per SIMD group; invalid values fall back to 2.
VMLX_DSV4_MXFP4_SIMD_GROUPS1, 2, 4, or 8; 2Sets SIMD groups per native MXFP4 threadgroup; invalid values fall back to 2.
VMLX_DSV4_ALIGNED_MXFP41/true enables; disabledEnables the aligned MXFP4 Metal-kernel experiment. It cannot be combined with interleaved MXFP4.
VMLX_DSV4_INTERLEAVED_MXFP41/true enables; disabledEnables the interleaved MXFP4 Metal layout experiment.
VMLX_DSV4_INTERLEAVED_LANES1/true enables; disabledUses interleaved SIMD lanes; it has effect only with VMLX_DSV4_INTERLEAVED_MXFP4.
VMLX_DSV4_THREADGROUP_LUT1/true enables; disabledEnables the threadgroup lookup-table variant in the fused DeepSeek V4 Metal kernel.
VMLX_DSV4_FUSED_ROUTER0/false/off disables; enabledControls the fused route-selection implementation.
VMLX_DSV4_FUSED_HC40 disables; enabledControls the four-way fused HC projection path.
VMLX_DSV4_FUSED_HC_NORM1 enables; disabledEnables the fused HC normalization experiment.
VMLX_DSV4_FUSED_HC_Q8_TAILnon-off enables; disabledEnables the fused HC, routed-MoE, shared-Q8, and expansion decode tail when the exact tensor contract matches.
VMLX_DSV4_DSPARK_HEAD_GEMV0/false/off disables; enabledControls the native DSpark head GEMV when the selected kernel engine is native.
VMLX_DSV4_CACHE_WOA0/false disables; enabledCaches the evaluated dequantized grouped attention output-projection tensor. Disabling trades memory for repeated work.
VMLX_DSV4_CACHE_LM_HEAD0/false disables; enabledCaches the evaluated float32 language-model head. Disabling reduces retained memory and increases repeated work.
VMLX_DSV4_Q8_LM_HEADnon-off enables; disabledQuantizes the language-model head to the DeepSeek V4 Q8 path.
VMLX_DSV4_QUANTIZED_GROUPED_WOA0/false/off disables; enabledControls the quantized grouped attention output projection.
VMLX_DSV4_QUANTIZED_GROUPED_WOA_QATnon-off enables; disabledApplies activation QAT to the quantized grouped output projection experiment.
VMLX_DSV4_COMPILE_ATTN_PRE0/false/off disables; enabledControls compiled decode for attention input projection.
VMLX_DSV4_COMPILE_ATTN_POST0/false/off disables; enabledControls compiled decode for attention output projection.
VMLX_DSV4_COMPILE_ATTN_HC0/false/off disables; enabledControls compiled decode for the attention HC path.
VMLX_DSV4_COMPILE_FFN0/false/off disables; enabledControls compiled decode for the layer feed-forward tail.
VMLX_DSV4_COMPILE_MOE1 enables; disabledEnables compiled decode around MoE. This stricter opt-in is disabled by default.
VMLX_ENABLE_UNSAFE_COMPILE1/true enables; disabledEnables whole decode compilation despite known model-switch corruption risk. Controlled benchmarks only; never a safe production default.
MLXPRESS_ENABLE_UNSAFE_COMPILE1/true enables; disabledLegacy alias for VMLX_ENABLE_UNSAFE_COMPILE.
VMLX_SHARED_GATE_UP_ACTIVATION0/false disables; enabledControls reuse of the shared gate/up activation in SwitchGLU.
VMLX_FUSED_GATE_UP_CACHE_LIMIT_BYTESinteger bytes; unsetSets the fused gate/up cache limit and takes precedence over the megabyte form. A negative value means unlimited.
VMLX_FUSED_GATE_UP_CACHE_LIMIT_MBinteger MiB; 512Limits duplicated fused gate/up weights. A negative value means unlimited.
BENCH_NO_FUSED_GATE_UP1 disables; offDisables the fused gate/up weight cache for A/B benchmarks.
BENCH_FUSED_GATE_UP_THRESHOLDinteger route count; 32Changes the decode-shaped route-count threshold for using fused gate/up weights.
VMLX_DSV4_STAGE_PROFILE1; offPrints fine-grained DeepSeek V4 and SwitchGLU stage timings.
VMLX_DSV4_OUTER_PROFILE1; offPrints aggregate transformer-build/eval and language-head-build/eval timings.
VMLX_DSV4_NUMERIC_TRACE1; offPrints token IDs plus sample, mean, RMS, and maximum values for selected tensors. It forces evaluation and is very expensive.
VMLX_DSV4_LOAD_TRACE1; offPrints DeepSeek V4 model-loading trace events.
MLX_PROFILE_COMMAND_BUFFERS1; offEnables patched MLX command-buffer and operation-count profiling, including a process-end summary.

Inherited or AFM-managed variables

They appear in the runtime contract because AFM reads or sets them, but they are normally not user configuration.

VariableValues · defaultEffect
PWDshell working directoryInherited from the shell and used to resolve relative model and configuration paths after Metal-library discovery may change the process working directory.
MTL_CAPTURE_ENABLED1 when --gpu-capture is activeSet internally before MLX initializes so Metal GPU capture can begin. Prefer --gpu-capture instead of setting it yourself.

Generated DwarfStar source paths

AFM derives the following bridge variables from AFM_DWARFSTAR_METAL_SOURCE_ROOT. Set the root rather than managing nineteen individual source paths:

  • DS4_METAL_FLASH_ATTN_SOURCE
  • DS4_METAL_DENSE_SOURCE
  • DS4_METAL_MOE_SOURCE
  • DS4_METAL_DSV4_HC_SOURCE
  • DS4_METAL_UNARY_SOURCE
  • DS4_METAL_DSV4_KV_SOURCE
  • DS4_METAL_DSV4_ROPE_SOURCE
  • DS4_METAL_DSV4_MISC_SOURCE
  • DS4_METAL_ARGSORT_SOURCE
  • DS4_METAL_CPY_SOURCE
  • DS4_METAL_CONCAT_SOURCE
  • DS4_METAL_GET_ROWS_SOURCE
  • DS4_METAL_SUM_ROWS_SOURCE
  • DS4_METAL_SOFTMAX_SOURCE
  • DS4_METAL_REPEAT_SOURCE
  • DS4_METAL_GLU_SOURCE
  • DS4_METAL_NORM_SOURCE
  • DS4_METAL_BIN_SOURCE
  • DS4_METAL_SET_ROWS_SOURCE

Precedence summary

ConcernWinnerFallback
Cache profile output--cache-profile-pathMACAFM_CACHE_PROFILE_PATH, then AFM_CACHE_PROFILE_PATH
DeepSeek kernel engine--mlx-kernels via AFM_MLX_KERNELSVMLX_DSV4_KERNELS, then native
Fused gate/up cache limitVMLX_FUSED_GATE_UP_CACHE_LIMIT_BYTESVMLX_FUSED_GATE_UP_CACHE_LIMIT_MB, then 512 MiB
Unsafe whole-decode compileVMLX_ENABLE_UNSAFE_COMPILEMLXPRESS_ENABLE_UNSAFE_COMPILE
Hugging Face discoveryHUGGINGFACE_HUB_CACHEHF_HUB_CACHE, HF_HOME, XDG_CACHE_HOME, then default cache