Loongkit

Updated at:

Loongkit is an OS extension component released by Alibaba Cloud. It provides software-hardware co-optimized acceleration with infrastructure-level tuning for AI scenarios such as text-to-image, text-to-video, image-to-video, autonomous driving, and embodied AI. Loongkit analyzes hardware resources, optimizes compute resource configurations, monitors the training process, and optimizes operator implementations to improve model training and inference efficiency and reduce resource waste.

Loongkit is compatible with mainstream frameworks such as PyTorch and MMCV, and individual optimization features target additional libraries. For the framework and version requirements of each feature, see Optimization features.

Environment requirements

Before you install Loongkit, make sure that your environment meets the following requirements:

  • Python — Version 3.10 or later.

  • PyTorch — Version 2.4.0 or later.

  • Operating system — Linux.

  • Source access — Loongkit is distributed through the AIEXT-Pro source, which requires authorization before you can install the package. For instructions, see Install Loongkit.

  • Feature-level requirements — Individual optimization features require specific framework, library, or kernel versions. For the requirements of each feature, see Optimization features.

Configure access permissions for the AIEXT-Pro source in ACS

Access to the AIEXT-Pro source from Container Compute Service (ACS) is authorized at the cluster level. Complete this authorization before you install Loongkit on PPU instances in an ACS cluster.

Authorize cluster-level access

  1. In the ACS console, select the target cluster from Cluster List.

  2. Choose Cluster Information > Basic Information > Security Audit, and then click PIP Password-Free Authorization.

  3. Generate the authorization URL, and then open it in a new browser page to complete the remaining authorization operations.

  4. Record the Service Account name of the ACS cluster. The Pod configuration in the next section refers to this name.

    After PIP Password-Free Authorization is enabled for a cluster, using a DinD Pod, a Buildah Pod, or a regular PPU Pod in this cluster meets the basic requirements for accessing the AIEXT-Pro source. Select the subsequent steps based on your use case.

Install the PIP software in a regular PPU container

  1. Modify the YAML file used to create the PPU Pod to add the spec.serviceAccountName field. Set this field to the Service Account name that you recorded in the previous section. In the following example, pip-default is a sample value.

***
    securityContext:
    privileged:true
# Specify the name of the ServiceAccount created in the previous step.
serviceAccountName: pip-default
volumes:
***
  1. In the regular PPU container, configure the environment required to use the PIP service:

# 1. First, install the password-free plugin aiext-pypi-plugin.
pip install aiext-pypi-plugin -i http://mirrors.cloud.aliyuncs.com/aiext-pypi/aiext-pypi-plugin/simple --trusted-host mirrors.cloud.aliyuncs.com

# 2. You can then install the related pip wheel packages as usual. For example:
pip install loongkit --extra-index-url=https://aiext-pypi.mirrors.aliyuncs.com/aiext-pro/pg1/simple/

Install Loongkit

Loongkit is distributed through the AIEXT-Pro source at https://aiext-pypi.mirrors.aliyuncs.com/aiext-pro. To access this source from an Elastic GPU Service (EGS) or ACS environment, you must submit a ticket to apply for whitelist access.

Select the tab that matches the environment where you run your training tasks.

ACS (PPU instances)

To access https://aiext-pypi.mirrors.aliyuncs.com/aiext-pro from an ACS environment, you must complete cluster-level authorization and modify the container YAML configuration. For more information, see Configure access permissions for the AIEXT-Pro source in ACS.

pip install aiext-pypi-plugin -i http://mirrors.cloud.aliyuncs.com/aiext-pypi/aiext-pypi-plugin/simple --trusted-host mirrors.cloud.aliyuncs.com
pip install loongkit --extra-index-url=https://aiext-pypi.mirrors.aliyuncs.com/aiext-pro/pg1/simple/
# When using PPU SDK 2.0 or earlier, use the following install command
pip install loongkit==0.8.1+ppu1.6.0.cu126 --extra-index-url=https://aiext-pypi.mirrors.aliyuncs.com/aiext-pro/pg1/simple/

EGS

If you use uv, after installing aiext-pypi-plugin, you must first run pip install pip -i https://aiext-pypi.mirrors.aliyuncs.com/aiext-pro/simple/ once to trigger authentication. Afterward, uv can use the AIEXT-Pro source normally.

pip install aiext-pypi-plugin -i http://mirrors.cloud.aliyuncs.com/aiext-pypi/aiext-pypi-plugin/simple --trusted-host mirrors.cloud.aliyuncs.com
pip install loongkit --extra-index-url=https://aiext-pypi.mirrors.aliyuncs.com/aiext-pro/simple/

Enable Loongkit

Loongkit provides three loading methods: the loongkit-run launcher, environment variables, and code modification. You can use any one of them. Choose the method that matches the control you have over the training startup:

Scenario Loading method
You can change the training command and want Loongkit to locate its own module path. loongkit-run launcher (Recommended)
You manage PYTHONPATH yourself and set environment variables outside the training command. Environment variables
You cannot change the training command, but you can change the training code. import loongkit.all in the training script

The following rules apply to all three loading methods:

  • No optimization features are enabled by default.

  • The LOONGKIT_xxx series of environment variables controls the enabling, disabling, and configuration of each optimization feature. LOONGKIT_ALL=X enables all optimization features at optimization level X and below, where X is 1, 2, or 3. The default value of LOONGKIT_ALL is 0.

  • Higher optimization levels are more intrusive. Enable a lower level first to confirm that your training results are correct, and then raise the level. For the definition of each level and the level of each feature, see Optimization features.

  • For single-GPU training tasks that do not use torchrun, you must additionally set the environment variable LOCAL_RANK=0.

Launcher

The loongkit-run launcher bundled with the Loongkit package automatically detects the path of the loongkit/prelude module and runs the training task with the modified PYTHONPATH:

LOONGKIT_ALL=1 loongkit-run <training task command>

Environment variables

Adding the path of the loongkit/prelude module to the PYTHONPATH environment variable allows Loongkit to load automatically when a Python task starts:

PYTHONPATH=/usr/local/lib/python3.10/site-packages/loongkit/prelude/:$PYTHONPATH LOONGKIT_ALL=1 <training task command>

The path of the loongkit/prelude module depends on the base image configuration and the virtual environment configuration. You can obtain it by running python3 -c "import site; print(site.getsitepackages()[0])" inside the container. If it is inconvenient to determine this path, load Loongkit by using the launcher or the code modification method instead.

Code modification

Adding the following statement at the beginning of the training task script file also loads Loongkit:

import loongkit.all

Verify enabled features

After you enable Loongkit, a summary of enabled features is written to standard output and logs at the end of each training task. Use this summary to confirm that Loongkit is loaded and that each feature actually took effect. The summary lists the features that are enabled through environment variables and indicates their actual usage during training, in the following format:

============================ Loongkit Feature Summary ============================
Enabled Features                 Configurations
----------------------------------------------------------------------------------
data_container                 * None
data_prefetch                  * None
allow_tf32                     * None
fused_adam                       None
fused_adamw                    * None
numa_affinity                    {'allow_assymetric': False, 'allow_index': False}
==================================================================================

In the summary:

  • The first column lists all features that are enabled through environment variables.

  • The second column lists the advanced configuration parameters of each feature.

  • An asterisk (*) indicates that the feature actually took effect during training.

Advanced configuration

Loongkit uses environment variables as its configuration interface. You can change the behavior of Loongkit by setting environment variables in YAML files, on the command line, and so on.

Basic configuration interface

Environment variable Data type Default value Description
LOONGKIT_LOGLEVEL string warning Limits the level of logs that are output. Only logs at or above this level are written to the log file. Valid values (case-insensitive): debug, info, warning, error, critical. If this environment variable is set to any other value, the default level warning is used.
LOONGKIT_LOGDIR string None Specifies the location where output logs are stored. If the value is stdout or stderr, logs are written to standard output or standard error output. If the value is a directory path that already exists or can be created, the log files are written to that directory.

If LOONGKIT_LOGDIR is not specified, or an invalid directory path is specified, Loongkit tries the following paths in order:

  1. /var/log/loongkit

  2. /tmp/log/loongkit

    The first available directory is used to store the log files. If none of the preceding directories is available, logs are written to standard error output (stderr).

Recommended configurations for embodied model training

The following table lists the recommended configurations for common embodied model training scenarios.

Model Recommended configuration Notes
OpenVLA LOONGKIT_ALL=1 None
π0 LOONGKIT_ALL=3 None
DreamZero LOONGKIT_ALL=3 LOONGKIT_HF_ACC_COMPILE=1 None
FastWAM LOONGKIT_ALL=3 None
Wan2.2 LOONGKIT_ALL=3 LOONGKIT_DIFFSYNTH_GRADIENT_ACCUMULATION=1 Gradient accumulation improves training efficiency but changes the global batch size. You need to evaluate its impact on training results.
GR00T

NVIDIA GPU, ZW-810E: LOONGKIT_ALL=3 LOONGKIT_HF_ACC_COMPILE=1

ZW-M890P: LOONGKIT_ALL=3

LOONGKIT_HF_ACC_COMPILE=1 may hang when handling split-scan on ZW-M890P.
Cosmos 3 Nano LOONGKIT_ALL=3 None

Optimization features

All optimization features are classified into the following levels and can be enabled in batches by setting LOONGKIT_ALL=X, where X is 1, 2, or 3:

  • Level 1 (Basic optimization) — Equivalent optimizations built on known versions of mainstream frameworks. Functional behavior remains largely unchanged, and under default configurations these optimizations typically do not cause performance degradation.

  • Level 2 (Advanced optimization) — Optimizations that require some experience, or must be combined with other tools, to be configured correctly across different scenarios. If parameters or configurations are chosen improperly, they may have a negative impact on performance.

  • Level 3 (Deep optimization) — Optimizations that change the way some common modules are implemented and represent more low-level or structural adjustments. If your model implementation differs significantly from the open-source version, you may encounter functional incompatibilities or abnormal results.

    The following table lists all optimization features. For features that have a dedicated tuning topic, the Notes column links to that topic.
Category Environment variable Data type Default value Optimization level Description Version requirements Notes
None LOONGKIT_ALL int 0 None Enables all optimization features at the specified optimization level and below. See the version requirements of each feature. None
Data preprocessing LOONGKIT_DATA_CONTAINER bool 0 1 Enables pin_memory support for MMCV DataContainer. 1.7.0 ≤ mmcv ≤ 1.8.0 Automatically enables the pin_memory feature of PyTorch DataLoader.
Data preprocessing LOONGKIT_DATA_PREFETCH bool 0 1 Enables data prefetching, which depends on pin_memory support for DataContainer. 1.7.0 ≤ mmcv ≤ 1.8.0 The peak GPU memory usage increases by an amount equivalent to the volume of data required for one iteration.
Data preprocessing LOONGKIT_MMENGINE_DATA_PREFETCH bool 0 1 Enables data prefetching adapted for MMCV 2.x. mmcv ≥ 2.0 and mmengine ≥ 0.8.0 None
Data preprocessing LOONGKIT_IMNORMALIZE bool 0 3 Improves the efficiency of the image normalization operator running on the CPU during data preprocessing. None Introduces just-in-time compilation when the data process loads data for the first time, incurring a one-time compilation overhead.
Data preprocessing LOONGKIT_DISTORTION bool 0 3 Improves the efficiency of the random image distortion operator running on the CPU during data preprocessing. None None
Data preprocessing LOONGKIT_PYTORCH bool 0 1 Improves the memory management efficiency of PyTorch DataLoader during data preprocessing. None None
Resource control LOONGKIT_NUMA_AFFINITY bool 0 1 Enables the active NUMA affinity setting of Loongkit to ensure that the training process always runs on the same NUMA node as the GPU. None For more information, see Advanced settings for NUMA affinity.
Resource control LOONGKIT_SUBCGROUPS bool 0 Manual only Divides training and data processes into different sub-cgroups based on NUMA affinity, allowing other resource control tools to further adjust the available resources for each type of process. None When this feature is enabled, the active NUMA affinity setting (that is, LOONGKIT_NUMA_AFFINITY) is automatically disabled.
Resource control LOONGKIT_CONFIG_GUARDS bool 0 1 Checks configurations such as the thread pool size, the number of data workers, and the number of compilation threads, and issues an alert when they may exceed the capacity of the hardware resources. torch ≥ 2.1.0 For more information, see Training task configuration check.
Resource control LOONGKIT_PAGE_CACHE_LIMIT bool 0 2 Automatically sets a page cache limit for the root memcg of the current container, mitigating performance fluctuations caused by memory fragmentation. Alibaba Cloud Linux (Alinux), kernel version ≥ 5.10.134-14 For more information, see Configure page cache limits.
Model compilation feature fixes LOONGKIT_TORCH_COMPILE_BACKPORTS bool 0 1 Backports upstream PyTorch model compilation feature fixes to older PyTorch versions. See Upstream model compilation feature fixes. See Upstream model compilation feature fixes.
Operator optimization and model compilation LOONGKIT_COMPILE_RESNET bool 0 1 Compiles the ResNet subnetwork. torch ≥ 2.6.0 and 1.0.0 ≤ mmdet ≤ 3.3.0 Model compilation introduces additional startup compilation time and GPU memory overhead, the extent of which depends on the complexity of the compiled model.
Operator optimization and model compilation LOONGKIT_FUSED_ADAMW bool 0 1 Uses the AdamW optimizer implementation with fused operators. torch ≥ 2.4.0 None
Operator optimization and model compilation LOONGKIT_OPENVLA bool 0 1 Compiles the Llama2 module. torch ≥ 2.6.0 None
Operator optimization and model compilation LOONGKIT_COMPILE_MMDET_MODULES bool 0 1 Compiles some algorithm modules registered to mmdet.models.builder.MODELS. torch ≥ 2.6.0 and 2.12.0 ≤ mmdet ≤ 2.28.3 Compiles CollisionLoss by default. You can use the environment variable LOONGKIT_COMPILE_MMDET_MODULES_FILTER to specify the names of the modules to compile, separating multiple modules with commas.
Operator optimization and model compilation LOONGKIT_DICE_LOSS bool 0 1 Uses the GPU-based optimized implementation of DiceLoss. 0.12.0 ≤ mmseg ≤ 1.0.0 None
Operator optimization and model compilation LOONGKIT_DAG bool 0 1 Optimizes the Deformable Aggregation algorithm module. None None
Operator optimization and model compilation LOONGKIT_VOXELIZATION bool 0 3 Improves the execution efficiency of the voxelization operator hard_voxelize in the mmdet3d library on the GPU. None For more information, see Voxelization operator (VOXELIZATION) optimization.
Operator optimization and model compilation LOONGKIT_BEVFORMER bool 0 1 Optimizes algorithm modules introduced by BEVFormer, such as SpatialCrossAttention and TemporalSelfAttention. None Applies to models that use the native related modules of BEVFormer.
Operator optimization and model compilation LOONGKIT_UNIAD bool 0 1 Optimizes some algorithm modules used in UniAD. None None
Operator optimization and model compilation LOONGKIT_BEVFUSION bool 0 3 Optimizes some algorithm modules used in BEVFusion. None Applies to models that use the native related modules of BEVFusion.
Operator optimization and model compilation LOONGKIT_HF_ACC_COMPILE bool 0 Manual only Supports torch.compile training acceleration for HuggingFace Accelerate and automatically enables the inductor compilation backend. None Fixes the compilation crash caused by the FA2 attention_interface call in transformers 4.57.* versions.
Operator optimization and model compilation LOONGKIT_INDUCTOR_PLUGIN bool 0 1 Enables the Loongkit model compilation plugin. When compiling models in max-autotune mode, the plugin uses PPU-optimized high-performance GEMM implementations. torch ≥ 2.9.0 PPU instances only.
Operator optimization and model compilation LOONGKIT_COMPILE_PI0PYTORCH bool 0 1 Compiles the PyTorch policy module of pi0. torch ≥ 2.6.0 Model compilation introduces additional startup compilation time and GPU memory overhead, the extent of which depends on the complexity of the compiled model.
Operator optimization and model compilation LOONGKIT_FASTWAM bool 0 3 Optimizes some algorithm modules used in FastWAM. None Applies to models that use the native related modules of FastWAM.
Operator optimization and model compilation LOONGKIT_DIFFSYNTH_GRADIENT_ACCUMULATION bool 0 Manual only Enables gradient accumulation for DiffSynth-Studio Wan video model training to improve training efficiency by increasing the global batch size. None You can configure the accumulation steps by using LOONGKIT_DIFFSYNTH_GRADIENT_ACCUMULATION_STEPS. The default value is 8.
Operator optimization and model compilation LOONGKIT_DIFFSYNTH bool 0 3 Enables all optimization features for training DiffSynth-Studio Wan video models, including DeepSpeed ZeRO-2 configurations, gradient accumulation, selective compilation of Wan DiT, disabling gradient checkpointing, and data loading configurations. None Applies to scenarios where Wan2.2 models are trained by using DiffSynth-Studio.
Operator optimization and model compilation LOONGKIT_DREAMZERO bool 0 3 Enables all optimization features for DreamZero training, including fixed-length offset optimization for FlashAttention, disabling gradient checkpointing, gradient accumulation, and teacher-forcing attention merging. None Applies to DreamZero training tasks.
Operator optimization and model compilation LOONGKIT_GR00T bool 0 3 Enables all optimization features for GR00T model training, including asynchronous transfer of training input data, video and Parquet data loading pipelines, the fast path for the Qwen3-VL backbone, and ZeRO-2 communication pipelining. None Applies to models that use the native related modules of Isaac GR00T N1.7.
Operator optimization and model compilation LOONGKIT_COSMOS_NANO bool 0 1 Optimizes the training efficiency of Cosmos Nano models, including operator fusion, attention operator optimization, and selective gradient checkpointing to balance training efficiency and GPU memory usage. cosmos-framework = 1.2.2 Applies to models that use the native related modules of Cosmos Nano.
Precision control LOONGKIT_ALLOW_TF32 bool 0 1 Uses TF32 precision to compute matrix multiplications and convolutions that use FP32 precision. torch ≥ 2.0.0 TF32 has the same representable range as FP32 but retains only half of the FP32 mantissa, so you need to assess whether the model requires the high precision of FP32.

Environment variables of the bool type accept 1, on, and yes as true, and 0, off, and no as false. Any other value is treated as undefined, and the default value is used.

Hardware-aware default optimization policies

The default values in the optimization features table are the values that apply when no optimization level is enabled. When you enable an optimization level, Loongkit automatically applies default optimization policies tailored to the detected hardware. The specific policies are listed in the following tables.

CPU architecture Optimization policy
Intel LOONGKIT_NUMA_AFFINITY: By default, only NUMA affinity is configured.
AMD / Hygon LOONGKIT_NUMA_AFFINITY: By default, LOONGKIT_NUMA_AFFINITY_PARTITION_PER_LLC is enabled.
GPU architecture Optimization policy
NVIDIA GPU LOONGKIT_FUSED_ADAMW is disabled. Enabling this feature on NVIDIA GPUs may reduce performance for some models.
T-Head PPU LOONGKIT_FUSED_ADAMW is enabled. This feature improves performance for all model types on PPUs.

Advanced settings for NUMA affinity

The configuration options related to NUMA affinity are summarized as follows:

Configuration option Format Default value Description Applicable conditions
LOONGKIT_NUMA_AFFINITY_ALLOW_INDEX bool 0 Forces CPU affinity settings to be enabled in environments where GPUs are not evenly distributed across NUMA nodes. For more information, see Compatibility between CUDA_VISIBLE_DEVICES and LOONGKIT_NUMA_AFFINITY_ALLOW_INDEX. PyTorch 2.4.0 and earlier, and CUDA_VISIBLE_DEVICES is not explicitly set.
LOONGKIT_NUMA_AFFINITY_PARTITION_PER_LLC bool Intel CPU: 0. AMD / Hygon CPU: 1 Binds different training processes to physical cores associated with different L3 caches. For more information, see Further tuning for AMD and Hygon CPUs. AMD / Hygon CPU.
LOONGKIT_NUMA_AFFINITY_SEPARATE_BY_ROLES bool 0 Further isolates the L3 caches used by training and data processes. The CPU utilization of the training task is less than 50%.
LOONGKIT_NUMA_AFFINITY_TRAIN_ON_GPULESS bool 0 Allows training processes to use NUMA nodes without GPU connections. For more information, see Further tuning on asymmetric architectures.
LOONGKIT_NUMA_AFFINITY_DATA_WORKER_ON_GPULESS bool 0 Allows data processes to use NUMA nodes without GPU connections.
LOONGKIT_NUMA_AFFINITY_DATA_WORKER_GPULESS_ONLY bool 0 Runs data processes only on NUMA nodes without GPU connections.

Compatibility between CUDA_VISIBLE_DEVICES and LOONGKIT_NUMA_AFFINITY_ALLOW_INDEX

By default, the NUMA affinity settings of Loongkit take effect on PyTorch 2.5.0 or later when GPUs are evenly distributed across NUMA nodes. Under these conditions, the settings automatically adapt to the CUDA_VISIBLE_DEVICES configuration.

For PyTorch 2.4.0 and earlier, you can set LOONGKIT_NUMA_AFFINITY_ALLOW_INDEX=1 to enable NUMA affinity settings. In this case, avoid configuring CUDA_VISIBLE_DEVICES. Otherwise, the NUMA affinity settings of training processes may become misaligned and reduce training efficiency.

Further tuning for AMD and Hygon CPUs

The microarchitectures of AMD, Hygon, and similar CPUs use separate L3 caches, and physical cores incur different latencies when accessing different L3 caches. You can therefore set LOONGKIT_NUMA_AFFINITY_PARTITION_PER_LLC=1 to bind different training processes to physical cores associated with different L3 caches for further performance improvements. This setting takes effect only when the L3 caches within a NUMA node can be evenly distributed among the training processes on that node.

On L20N instances, when the overall CPU utilization of the training task does not exceed 50%, you can set LOONGKIT_NUMA_AFFINITY_SEPARATE_BY_ROLES=1 to isolate the L3 caches used by training and data processes, further reducing interference from data processes.

Further tuning on asymmetric architectures

Configuring NUMA affinity on platforms where GPUs are not evenly distributed across NUMA nodes requires jointly considering the CPU and memory demands of the training task and the hardware topology. Loongkit therefore enables NUMA affinity settings on these platforms only when LOONGKIT_NUMA_AFFINITY_ALLOW_ASYMMETRIC=1 is explicitly set. In this case, the affinity policy supports the following options:

  • LOONGKIT_NUMA_AFFINITY_TRAIN_ON_GPULESS: Allows training processes to use NUMA nodes without GPU connections.

  • LOONGKIT_NUMA_AFFINITY_DATA_WORKER_ON_GPULESS: Allows data processes to use NUMA nodes without GPU connections.

  • LOONGKIT_NUMA_AFFINITY_DATA_WORKER_GPULESS_ONLY: Runs data processes only on NUMA nodes without GPU connections.

    The following example assumes the hardware topology shown in the figure and evaluates the training and data processes on GPU 2 under different combinations of the three options.

Example hardware topology used to evaluate NUMA affinity options for the training and data processes on GPU 2

In the following table, TRAIN_ON_GPULESS, DATA_WORKER_ON_GPULESS, and DATA_WORKER_GPULESS_ONLY refer to LOONGKIT_NUMA_AFFINITY_TRAIN_ON_GPULESS, LOONGKIT_NUMA_AFFINITY_DATA_WORKER_ON_GPULESS, and LOONGKIT_NUMA_AFFINITY_DATA_WORKER_GPULESS_ONLY.

TRAIN_ON_GPULESS DATA_WORKER_ON_GPULESS DATA_WORKER_GPULESS_ONLY Training process affinity settings Data process affinity settings
0 0 Ignored NUMA 2 NUMA 2
0 1 0 NUMA 2 NUMA 2,3
0 1 1 NUMA 2 NUMA 3
1 0 Ignored NUMA 2,3 NUMA 2
1 1 0 NUMA 2,3 NUMA 2,3
1 1 1 NUMA 2,3 NUMA 3

To determine the optimal configuration for a specific hardware topology and training workload, submit a ticket to request a joint evaluation.

Training task configuration check

When you enable LOONGKIT_CONFIG_GUARDS to check the configuration of a training task, configuration exceptions are written to the Loongkit logs at the WARNING level. You can configure the log path by using LOONGKIT_LOGDIR.

Loongkit also provides automatic optimization of related settings to reduce the risk of overloading the training task. To enable this feature, also set LOONGKIT_CONFIG_GUARDS_APPLY_FIX=1.

Configuration option Format Default value Description
LOONGKIT_CONFIG_GUARDS_APPLY_FIX bool 0 Automatically optimizes the process and thread count configurations of the training task.

Configure page cache limits

After you enable LOONGKIT_PAGE_CACHE_LIMIT, you can further configure the behavior of the page cache limit by using the following environment variables:

Environment variable Data type Default value Description
LOONGKIT_PAGE_CACHE_LIMIT_SIZE string 50% The maximum page cache usage of the current container. The following three formats are supported: decimal numbers (representing the number of bytes, such as 10737418240); byte counts with units (such as 8G, 512M, or 1024K; case-insensitive); percentages (such as 50%, which represents the proportion of available memory in the current container).
LOONGKIT_PAGE_CACHE_LIMIT_SYNC bool 0 Whether to use asynchronous reclaim or synchronous reclaim after the page cache usage of the current memcg exceeds the limit.

For more information about the page cache feature, see .

Upstream model compilation feature fixes

Loongkit backports recent upstream PyTorch community fixes to commonly used older PyTorch versions so that these versions can enable model compilation features more reliably. The following table lists the upstream fixes backported by Loongkit. Each fix can be controlled individually by the corresponding environment variable.

Environment variable Data type Default value Optimization level Description Version requirements Auto-enabled by LOONGKIT_TORCH_COMPILE_BACKPORTS=1
LOONGKIT_DYNAMIC_SHAPE_FIX bool 0 1 Fixes the crash that occurs when PyTorch 2.9.x compiles models with dynamic dimensions. torch 2.9.0–2.11.x Yes
LOONGKIT_DONATED_BUFFER_FIX bool 0 1 Fixes the issue where DDPOptimizer silently overwrites weights under PyTorch 2.6–2.8, and automatically disables donated_buffer. torch 2.6.0–2.8.x Yes
LOONGKIT_INDUCTOR_INT32_OVERFLOW_FIX bool 0 1 Fixes the compilation failure caused by address calculations exceeding the 32-bit integer range after operator fusion. torch 2.8.0–2.12.x Yes
LOONGKIT_INDUCTOR_GEMM_EPILOGUE_TRUNCATION_FIX bool 0 1 Fixes the numerical deviation caused by GEMM epilogue fusion. torch 2.9.0–2.12.x Yes
LOONGKIT_INDUCTOR_SYMBOL_ALIAS_FIX bool 0 1 Fixes the compilation failure caused by dynamic tensors reporting "use of undeclared identifier". torch 2.12.x No
LOONGKIT_INDUCTOR_TILING_FIX bool 0 1 Fixes the internal AssertionError that dynamic tensors may trigger during model compilation. torch 2.8.0–2.13.x Yes

Voxelization operator (VOXELIZATION) optimization

Loongkit provides a GPU-accelerated implementation of the hard_voxelize voxelization operator that is commonly used in 3D object detection and BEV perception models. This optimization reduces point cloud preprocessing time by replacing the native voxelization implementations in mmcv, mmdet3d, and BEVFusion with the optimized version. You can enable the voxelization optimization by using the following command:

export LOONGKIT_VOXELIZATION=1

After you enable this feature, Loongkit automatically detects and replaces the following three types of native implementations. Whichever implementation is detected is replaced, and the replacements do not affect each other:

No. Patch path Activation condition Default coors order Can be overridden by COORS_ORDER
① BEVFusion: projects.BEVFusion.bevfusion.ops.voxel.voxelize.hard_voxelize BEVFusion is present in the environment. xyz (native BEVFusion contract) No. The order is always xyz.
② mmcv._ext.hard_voxelize_forward (shared by mmcv and mmdet3d; a single patch covers both paths) mmcv can be loaded in the environment. zyx (native mmcv and mmdet3d contract) Yes. Can be changed to xyz.
③ <module>._Voxelization.forward The environment variable LOONGKIT_VOXELIZATION_VOXELIZE_MODULE is set. xyz Yes. Can be changed to zyx (aligned with the native mmcv forward).

Option ③ is used when the native mmcv-style voxelization entry is not matched by option ②. You must explicitly specify the import path of the module, and the module must contain a _Voxelization.forward method with the same signature as mmcv. For example:

export LOONGKIT_VOXELIZATION_VOXELIZE_MODULE=<your_package>.ops.voxelize

In the preceding table, coors refers to the voxel coordinate output. For example, _Voxelization.forward() returns coors_out as its second value, with a shape of (number of voxels, 3). Each row is the grid index of one voxel. The column order zyx indicates [z_idx, y_idx, x_idx], and xyz indicates [x_idx, y_idx, z_idx]. You can globally specify the order by using LOONGKIT_VOXELIZATION_COORS_ORDER, which applies to both option ② and option ③.

Examples:

# Scenario 1: Enable voxelization optimization only
export LOONGKIT_VOXELIZATION=1

# Scenario 2: Enable the optimization and change the output order of option ② to xyz
export LOONGKIT_VOXELIZATION=1
export LOONGKIT_VOXELIZATION_COORS_ORDER=xyz

# Scenario 3: Explicitly specify the module path of option ③ and change the output order to zyx
export LOONGKIT_VOXELIZATION=1
export LOONGKIT_VOXELIZATION_VOXELIZE_MODULE=<your_package>.ops.voxelize
export LOONGKIT_VOXELIZATION_COORS_ORDER=zyx
  • LOONGKIT_VOXELIZATION_COORS_ORDER values are case-insensitive, and spaces are automatically removed. If the value is neither xyz nor zyx, a warning is printed and none of the three patch types take effect.

  • Option ③ takes precedence over option ②. When both are matched, the output of option ③ is used.

FAQ

What is the runtime overhead of Loongkit itself?

When no features are enabled, the loading time of Loongkit itself (excluding the time required to import PyTorch) does not exceed 50 ms, and its system memory consumption does not exceed 10 MB.

For the runtime overhead of the optimization features, see Optimization features.

Are there other ways to enable Loongkit without changing the training command?

In addition to using loongkit-run, you can load Loongkit by adding import loongkit.all at the beginning of the entry file of your training code. The feature configuration takes effect as of the point when import loongkit.all is executed. You can change the Loongkit-related environment variables in a YAML file or by adjusting the os.environ dictionary before that line of code.

How do I select the optimization features that target a specific model?

Loongkit provides targeted optimization features for common vision-language-action (VLA) models, world action models (WAM), and autonomous driving perception models. If you have not made major changes to the model structure or the training code, you can refer to the recommended configurations table in Recommended configurations for embodied model training and enable the corresponding environment variable for your model.

The preceding features apply to the native implementations of the models. If you have modified the related modules, we recommend that you verify the effect in a small-scale task first. In addition to the targeted features, general features such as data preprocessing, resource control, and operator optimization also apply to the preceding models. For more information, see Optimization features.