HAMi (Heterogeneous AI Computing Virtualization Middleware)
repository·master·Indexed 23 days ago
https://github.com/project-hami/hamiA Kubernetes-native solution for GPU virtualization and heterogeneous accelerator scheduling. HAMi enables sharing AI accelerators (GPUs, NPUs, etc.) across multiple workloads with resource isolation and device-aware scheduling without requiring application code changes. It supports a wide range of hardware including NVIDIA, Cambricon MLU, Hygon DCU, Metax GPU, Enflame GCU, Kunlunxin XPU, AWS Neuron, Huawei Ascend, and Iluvatar devices.
What's inside HAMi
- HAMi is a Kubernetes middleware designed for heterogeneous AI device sharing, isolation, and scheduling. It enables efficient management of GPUs, NPUs, and other accelerators across a Kubernetes cluster.
Overview of HAMi (Heterogeneous AI Computing Virtualization Middleware)
masterHAMi is a Kubernetes-native middleware designed for GPU virtualization and heterogeneous accelerator scheduling in AI infrastructure. It allows platform teams to share expensive GPUs and other AI accelerators across Kubernetes workloads by partitioning device memory and compute.
Key capabilities include:
- Device Sharing: Allocate portions of physical accelerators based on memory, cores, or device count.
- Resource Isolation: Enforce memory and compute limits per workload (if supported by the backend).
- Device-Aware Scheduling: Support for topology-aware, binpack, spread, and device-specific scheduling policies.
- Heterogeneous Support: Manage multiple accelerator types (NVIDIA GPU, NPU, DCU, MLU, etc.) through a single workflow.
- No Application Changes: Uses standard Kubernetes resource requests and limits.
Use the HAMi vGPU Metrics Summarizer skill
masterThe
hami_vgpu_metrics_summarizeris an analysis skill designed to process HAMi vGPU metrics (from Prometheus-style/metricsoutput) to provide a structured summary of GPU resource usage.It can analyze:
- Raw HAMi Prometheus metrics pasted directly by the user.
- Metrics collected from a live Kubernetes cluster.
The tool produces reports on:
- Node and GPU usage status.
- Per-GPU core and memory allocation.
- Allocation-based utilization per GPU.
- Sharing density (number of containers sharing each GPU).
- Pod and namespace consumption.
- Namespace-level totals for
gpucoresandgpumem. - Cluster capacity and resource distribution patterns (concentrated, fragmented, or even).
Note: Unless explicit real-time GPU utilization metrics are provided, the tool treats metrics as allocation-based utilization, not actual SM/compute runtime utilization from
nvidia-smi.Understand HAMi GPU Resource Accounting for Init Containers
masterHAMi implements a specific accounting logic for Pods that contain both init containers and app containers. Because Kubernetes runs init containers sequentially before app containers, they do not overlap in execution.
To prevent over-provisioning or incorrect scheduling rejections, HAMi calculates the effective GPU footprint of a pod using the following formula for each resource dimension (GPU count, memory, cores, and per-device UUID):
effective = max( sum(app container requests), max(single init container request) )This ensures that if an init container requests 20Gi and an app container requests 10Gi, HAMi accounts for 20Gi of usage rather than the sum (30Gi), reflecting the actual peak resource usage.
Understand the HAMi Architecture
masterHAMi operates as a 'chart' architecture consisting of four primary components that manage the lifecycle of pod scheduling and device allocation:
- MutatingWebhook: Intercepts pod creation to validate resource requests. If HAMi recognizes the requested sharable devices, it sets the
schedulerNametoHAMi scheduler. Otherwise, it allows the task to pass to the default Kubernetes scheduler. - Scheduler: An extender for
kube-schedulerorvolcano-scheduler. It implementsFilter(to find nodes with available sharable devices) andScore(to rank those nodes) methods. The decision is communicated via pod annotations. - DevicePlugin: A customized Device Plugin (DP) that runs on the node. Once the scheduler makes a decision, the DP generates the necessary environment variables and volume mounts based on the pod annotations.
- InContainer Control: Manages hard limits within the container. This is device-specific (e.g.,
HAMi-Corefor NVIDIA devices,libvgpu-control.sofor Iluvatar devices) and relies on specific environment variables passed during the scheduling process.
- MutatingWebhook: Intercepts pod creation to validate resource requests. If HAMi recognizes the requested sharable devices, it sets the
How HAMi handles Init Container resource accounting
masterHAMi applies the effective resource formula across three main stages of the Pod lifecycle:
- Admission (Quota Check): The
fitResourceQuotacheck uses theeffectiveReq(the maximum of the peak init container request or the sum of app container requests) to validate against namespace quotas. Note that currently, GPU count is computed for consistency but is not used as an independent quota dimension; only memory and cores are checked against quotas. - Scheduling (Fit & Scoring): The scheduler performs two passes. First, it fits init containers independently against a fresh copy of node state to find the peak per-device usage. Second, it fits app containers cumulatively. It then merges these results using the
max()function per device UUID. - Usage Recording: HAMi collapses raw per-container
PodDevicesinto an accounting-only view usingCollapseInitContainerUsage. This prevents the usage tracker from summing init and app container requests simultaneously.
- Admission (Quota Check): The
Diagnose ImagePullBackOff and ErrImagePull
masterIf pods fail to start due to image issues, verify the image reference and pull errors.
Common Error Patterns:
repository does not exist: Verify the image name and tag.unauthorized: FiximagePullSecretsto provide credentials.manifest unknown: Verify the tag exists in the registry.connection refused: Check network/DNS connectivity to the registry.x509: certificate: Fix the CA trust chain.
Verification Commands:
- Check the image being used.
- Inspect pod events for specific pull errors.
- Verify if
imagePullSecretsare configured for private registries.
Troubleshoot Pending Pods (Scheduling Failures)
masterIf pods are stuck in the
Pendingstate, usekubectl describe podto inspect theEventsandConditionssections.Common Causes and Remediation:
- Insufficient cpu/memory: Resource exhaustion. Reduce requests, scale the cluster, or check resource quotas.
- Taint/toleration mismatch:
0/N nodes are available+ taint. Add a toleration to the pod or untaint the node. - Node selector mismatch:
0/N nodes are available+ node selector. Fix thenodeSelectoror add matching nodes. - Affinity rule unsatisfiable:
0/N nodes are available+ affinity. Relax affinity rules. - Missing PVC:
persistentvolumeclaim "X" not found. Create the PVC or fix the claim name. - Unbound PVCs:
pod has unbound immediate PersistentVolumeClaims. CheckStorageClassand PV availability. - Quota limit hit:
exceeded quota. Check resource quotas.
kubectl describe pod <pod-name> -n <namespace>Generate a HAMi vGPU Usage Summary Report
masterA comprehensive vGPU usage report should follow a structured template to provide both high-level cluster status and granular workload analysis. The recommended structure is:
- Executive Summary: A one-paragraph overview of the cluster state.
- Cluster / Node Overview: Node count, GPU count, and total core/memory allocation ratios.
- Per-GPU Summary: A table including Node, GPU Index, UUID, Core/Mem Allocated vs Limit, Core %, Mem %, Shared Containers, and Status.
- Per-Namespace Summary: Namespace usage of cores and memory (MiB/GiB), core/memory share %, and main pods.
- Pod / Workload Breakdown: Detailed mapping of Namespace, Pod, Container, Node, GPU UUID, Core, Memory, and Allocation Type.
- Real vs. Allocated Usage (nvidia-smi): Comparison of actual GPU utilization and memory used (via
nvidia-smi) against the allocated reservation to identify over-allocated or idle pods. - Capacity & Scheduling Assessment: Identification of idle, fully allocated, and fragmented GPUs, and whether new jobs (full or fractional) can fit.
- Key Findings & Caveats.
Install HAMi via Helm
masterTo install HAMi on your Kubernetes cluster, follow these steps:
- Label GPU nodes: HAMi requires nodes to be labeled so it can manage them.
- Add the Helm repository: Add the official
hami-chartsrepository. - Install the chart: Deploy HAMi into the
kube-systemnamespace. - Verify installation: Ensure both
hami-device-pluginandhami-schedulerare in theRunningstate.
Prerequisites for NVIDIA users:
- NVIDIA driver >= 440
nvidia-dockerversion > 2.0- NVIDIA configured as the default runtime (containerd, Docker, or CRI-O)
- Kubernetes >= 1.23
- glibc >= 2.17
- Linux kernel >= 3.10
- Helm > 3.0
Install HAMi using Helm
masterFollow these steps to install HAMi on your Kubernetes cluster.
Prerequisites (for NVIDIA devices):
- NVIDIA Driver >= 440
nvidia-docker> 2.0- NVIDIA configured as default runtime (containerd, Docker, or CRI-O)
- Kubernetes >= 1.23
- glibc >= 2.17
- Linux Kernel >= 3.10
- Helm > 3.0
Installation Steps:
- Label your GPU nodes to allow HAMi management:
kubectl label nodes <node-name> gpu=on - Add and update the HAMi Helm repository:
helm repo add hami-charts https://project-hami.github.io/HAMi/ helm repo update - Install HAMi into the
kube-systemnamespace:helm install hami hami-charts/hami -n kube-system - Verify that
hami-device-pluginandhami-schedulerare running:kubectl get pods -n kube-system - Deploy a sample workload to test:
kubectl apply -f examples/nvidia/default_use.yaml
kubectl label nodes <node-name> gpu=on helm repo add hami-charts https://project-hami.github.io/HAMi/ helm repo update helm install hami hami-charts/hami -n kube-system kubectl get pods -n kube-system kubectl apply -f examples/nvidia/default_use.yamlUse Customized Device Plugins for HAMi
masterTo ensure proper device virtualization and resource allocation, you must use the customized Device Plugin (DP) provided by HAMi for your specific hardware. Standard official Kubernetes Device Plugins are generally incompatible with HAMi and will cause unexpected behavior.
Refer to the main README for installation instructions specific to your device type.