[error] Mapping Failed (allocation time: 2s)

Hello. I got an error when converting from onnx to hef. The conversion code and error are as follows:
I have tried removing ‘performance_param(compiler_optimization_level=max)’ and setting optimization_level=0, compression_level=0, but the same error message appears.
conversion code:

import hailo_sdk_client
from hailo_sdk_client import ClientRunner
import numpy as np
import os
import logging
import traceback

# 设置日志级别为 DEBUG 以获取更多信息
logging.basicConfig(
    level=logging.DEBUG,
    format='%(asctime)s - %(levelname)s - %(message)s',
    handlers=[
        logging.FileHandler('hailo_quantization.log'),
        logging.StreamHandler()
    ]
)

os.environ["HAILO_DFC_LOG_LEVEL"] = "DEBUG"

# --- 1. Hailo 硬件架构 ---
chosen_hw_arch = "hailo8"

# --- 2. 模型路径和文件名 ---
onnx_model_name = "head_singleframe_simplified_model"
onnx_path = "/home/ubuntu/ycy/head_singleframe_simplified_model.onnx"  # 更新为简化后的模型
output_dir = "/home/ubuntu/ycy/onnx_models/hailo_outputs"
hailo_model_har_path = os.path.join(output_dir, f"{onnx_model_name}_hailo_model.har")
hailo_quantized_har_path = os.path.join(output_dir, f"{onnx_model_name}_hailo_quantized_model.har")
hailo_model_hef_path = os.path.join(output_dir, f"{onnx_model_name}.hef")

# --- 3. 确保输出目录存在 ---
os.makedirs(output_dir, exist_ok=True)

# --- 4. 初始化 Hailo ClientRunner ---
try:
    runner = ClientRunner(hw_arch=chosen_hw_arch)
    print(f"✅ Initialized ClientRunner with hardware architecture: {chosen_hw_arch}")
except Exception as e:
    print(f"❌ Failed to initialize ClientRunner: {e}")
    exit(1)

# --- 5. 验证 ONNX 模型文件存在 ---
if not os.path.exists(onnx_path):
    print(f"❌ ONNX model file not found: {onnx_path}")
    exit(1)
print(f"✅ ONNX model file found: {onnx_path}")

# --- 6. 指定 ONNX 模型的多个输入节点 ---
net_input_shapes = {
    "inst_dfg0": (1, 900, 512),  # 假设输入形状未变,需确认
    "anchor": (1, 900, 11),
    "anchor_embed": (1, 900, 256),
}

# --- 7. 转换 ONNX 模型为 HAR ---
try:
    hn, npz = runner.translate_onnx_model(
        model=onnx_path,
        net_name=onnx_model_name,
        net_input_shapes=net_input_shapes,
        start_node_names=list(net_input_shapes.keys())
    )
    print(f"✅ Successfully translated ONNX model to HAR")
except Exception as e:
    print(f"❌ Failed to translate ONNX model to HAR: {e}")
    traceback.print_exc()
    exit(1)

# --- 8. 保存 HAR 模型 ---
try:
    runner.save_har(hailo_model_har_path)
    print(f"✅ HAR model saved to: {hailo_model_har_path}")
except Exception as e:
    print(f"❌ Failed to save HAR model: {e}")
    exit(1)

# --- 9. 校准数据集准备 ---
def print_activation_ranges(model_layers):
    for layer in model_layers:
        print(f"{layer}: min={np.min(layer)}, max={np.max(layer)}")

def generate_calibration_dataset(num_samples: int = 64):
    calib_data_path = "/home/ubuntu/ycy/calib_data/calib_data.npz"
    
    hailo_input_names_mapping = {
        'inst_dfg0': 'head_singleframe_simplified_model/input_layer1',
        'anchor': 'head_singleframe_simplified_model/input_layer2',
        'anchor_embed': 'head_singleframe_simplified_model/input_layer3',
    }
    
    if os.path.exists(calib_data_path):
        print(f"✅ Loading real calibration data from {calib_data_path}")
        data = np.load(calib_data_path, allow_pickle=True)
        calib_data = data["calib_data"][:num_samples]

        inst_dfg0_array = np.stack([np.nan_to_num(s["inst_dfg0"], nan=0.0, posinf=0.0, neginf=0.0) / 10.0 for s in calib_data]).astype(np.float32)
        anchor_array = np.stack([np.nan_to_num(s["anchor"], nan=0.0, posinf=0.0, neginf=0.0) / 10 for s in calib_data]).astype(np.float32)
        anchor_embed_array = np.stack([np.nan_to_num(s["anchor_embed"], nan=0.0, posinf=0.0, neginf=0.0) / 0.1 for s in calib_data]).astype(np.float32)
        
        print(f"✅ Loaded {num_samples} real calibration samples.")

        calib_dataset = {
            hailo_input_names_mapping['inst_dfg0']: inst_dfg0_array,
            hailo_input_names_mapping['anchor']: anchor_array,
            hailo_input_names_mapping['anchor_embed']: anchor_embed_array,
        }
        
        print(f"✅ Generated calibration dataset shapes:")
        for name, data in calib_dataset.items():
            print(f"  - {name}: {data.shape}")
        
        return calib_dataset

    else:
        print(f"⚠️ Calibration data not found at {calib_data_path}, generating random data")
        
        random_data_dict = {
            hailo_input_names_mapping['inst_dfg0']: np.random.randn(num_samples, 1, 900, 512).astype(np.float32) / 10.0,
            hailo_input_names_mapping['anchor']: np.random.randn(num_samples, 1, 900, 11).astype(np.float32) / 100.0,
            hailo_input_names_mapping['anchor_embed']: np.random.randn(num_samples, 1, 900, 256).astype(np.float32) / 10.0,
        }

        print(f"✅ Generated random dataset shapes:")
        for name, data in random_data_dict.items():
            print(f"  - {name}: {data.shape}")
        
        print_activation_ranges(random_data_dict.values())
        
        return random_data_dict

calib_dataset = generate_calibration_dataset(num_samples=64)

# --- 10. 量化 HAR 模型 ---
runner = ClientRunner(har=hailo_model_har_path, hw_arch="hailo8")
alls_lines = [
    # Try increasing utilization to the maximum allowed
    #'resources_param(max_control_utilization=1.0, max_compute_utilization=1.0, max_memory_utilization=1.0)',
    # # 'performance_param(compiler_optimization_level=auto)',
    # 'model_optimization_flavor(optimization_level=0, compression_level=0)',
    'model_optimization_flavor(optimization_level=1, compression_level=0)',  # 提高优化级别
    'performance_param(compiler_optimization_level=max)'  # 平衡编译优化
]

print("--- Begin quantization ---")
runner.load_model_script('\n'.join(alls_lines))
try:
    # runner.optimize_full_precision(calib_dataset)
    runner.optimize(calib_dataset)  # 启用 fine_tune
    runner.save_har(hailo_quantized_har_path)
    print(f"✅ Quantized HAR model saved to: {hailo_quantized_har_path}")
except Exception as e:
    print(f"❌ Failed to quantize HAR model: {e}")
    traceback.print_exc()
    exit(1)

# --- 11. 导出 HEF 模型 ---
runner = ClientRunner(har=hailo_quantized_har_path, hw_arch="hailo8")
try:
    #runner.configure()
    compiled_hef = runner.compile()

    with open(hailo_model_hef_path, "wb") as f:
        f.write(compiled_hef)
        print(f"✅ HEF model exported to: {hailo_model_hef_path}")
except Exception as e:
    print(f"❌ Failed to compile HEF model: {e}")
    traceback.print_exc()
    exit(1)

error:

[info] No GPU chosen, Selected GPU 0
WARNING: All log messages before absl::InitializeLog() is called are written to STDERR
E0000 00:00:1756433816.665498  534661 cuda_dnn.cc:8310] Unable to register cuDNN factory: Attempting to register factory for plugin cuDNN when one has already been registered
E0000 00:00:1756433816.667989  534661 cuda_blas.cc:1418] Unable to register cuBLAS factory: Attempting to register factory for plugin cuBLAS when one has already been registered
[warning] Cannot use graphviz, so no visualizations will be created
✅ Initialized ClientRunner with hardware architecture: hailo8
✅ ONNX model file found: /home/ubuntu/ycy/head_singleframe_simplified_model.onnx
[info] Translation started on ONNX model head_singleframe_simplified_model
[info] Restored ONNX model head_singleframe_simplified_model (completion time: 00:00:00.02)
[info] Extracted ONNXRuntime meta-data for Hailo model (completion time: 00:00:00.05)
[info] Start nodes mapped from original model: 'inst_dfg0': 'head_singleframe_simplified_model/input_layer1', 'anchor': 'head_singleframe_simplified_model/input_layer2', 'anchor_embed': 'head_singleframe_simplified_model/input_layer3'.
[info] End nodes mapped from original model: '/layers.3/cls_layers/cls_layers.6/Add', '/layers.3/Concat', '/layers.3/quality_layers/quality_layers.6/Add'.
[info] Translation completed on ONNX model head_singleframe_simplified_model (completion time: 00:00:00.16)
✅ Successfully translated ONNX model to HAR
[info] Saved HAR to: /home/ubuntu/ycy/onnx_models/hailo_outputs/head_singleframe_simplified_model_hailo_model.har
✅ HAR model saved to: /home/ubuntu/ycy/onnx_models/hailo_outputs/head_singleframe_simplified_model_hailo_model.har
✅ Loading real calibration data from /home/ubuntu/ycy/calib_data/calib_data.npz
✅ Loaded 64 real calibration samples.
✅ Generated calibration dataset shapes:
  - head_singleframe_simplified_model/input_layer1: (64, 1, 900, 512)
  - head_singleframe_simplified_model/input_layer2: (64, 1, 900, 11)
  - head_singleframe_simplified_model/input_layer3: (64, 1, 900, 256)
--- Begin quantization ---
[info] ParsedPerformanceParam command, setting optimization_level(max=2)
[info] Loading model script commands to head_singleframe_simplified_model from string
[info] ParsedPerformanceParam command, setting optimization_level(max=2)
[info] Starting Model Optimization
I0000 00:00:1756433819.099177  534661 gpu_device.cc:2022] Created device /job:localhost/replica:0/task:0/device:GPU:0 with 20918 MB memory:  -> device: 0, name: NVIDIA GeForce RTX 4090, pci bus id: 0000:01:00.0, compute capability: 8.9
I0000 00:00:1756433819.298043  534661 gpu_device.cc:2022] Created device /job:localhost/replica:0/task:0/device:GPU:0 with 20926 MB memory:  -> device: 0, name: NVIDIA GeForce RTX 4090, pci bus id: 0000:01:00.0, compute capability: 8.9
[info] Model received quantization params from the hn
I0000 00:00:1756433819.589371  534661 gpu_device.cc:2022] Created device /job:localhost/replica:0/task:0/device:GPU:0 with 20926 MB memory:  -> device: 0, name: NVIDIA GeForce RTX 4090, pci bus id: 0000:01:00.0, compute capability: 8.9
I0000 00:00:1756433819.807364  534661 gpu_device.cc:2022] Created device /job:localhost/replica:0/task:0/device:GPU:0 with 20927 MB memory:  -> device: 0, name: NVIDIA GeForce RTX 4090, pci bus id: 0000:01:00.0, compute capability: 8.9
[info] MatmulDecompose skipped
[info] Starting Mixed Precision
[info] Model Optimization Algorithm Mixed Precision is done (completion time is 00:00:00.16)
[info] Starting LayerNorm Decomposition
[info] Using dataset with 64 entries for calibration
Calibration: 100%|███████████████████████████████████████████████████████████████████████████████████████████| 64/64 [00:02<00:00, 31.09entries/s]
[info] Model Optimization Algorithm LayerNorm Decomposition is done (completion time is 00:00:03.77)
[info] Starting Statistics Collector
[info] Using dataset with 64 entries for calibration
Calibration: 100%|███████████████████████████████████████████████████████████████████████████████████████████| 64/64 [00:08<00:00,  7.73entries/s]
[info] Model Optimization Algorithm Statistics Collector is done (completion time is 00:00:08.67)
[info] Starting Fix zp_comp Encoding
[info] Model Optimization Algorithm Fix zp_comp Encoding is done (completion time is 00:00:00.00)
[info] Matmul Equalization skipped
[info] Starting MatmulDecomposeFix
[info] Model Optimization Algorithm MatmulDecomposeFix is done (completion time is 00:00:00.00)
[info] No shifts available for layer head_singleframe_simplified_model/conv3/conv_op, using max shift instead. delta=0.7239
[info] No shifts available for layer head_singleframe_simplified_model/conv3/conv_op, using max shift instead. delta=0.3620
[info] No shifts available for layer head_singleframe_simplified_model/conv_feature_splitter2_1/conv_op, using max shift instead. delta=0.1388
I0000 00:00:1756433841.897990  534661 gpu_device.cc:2022] Created device /job:localhost/replica:0/task:0/device:GPU:0 with 20936 MB memory:  -> device: 0, name: NVIDIA GeForce RTX 4090, pci bus id: 0000:01:00.0, compute capability: 8.9
I0000 00:00:1756433842.510683  534661 gpu_device.cc:2022] Created device /job:localhost/replica:0/task:0/device:GPU:0 with 20936 MB memory:  -> device: 0, name: NVIDIA GeForce RTX 4090, pci bus id: 0000:01:00.0, compute capability: 8.9
[info] Finetune encoding skipped
[info] Starting Bias Correction
[info] The algorithm Bias Correction will use up to 0.83 GB of storage space
[info] Using dataset with 64 entries for Bias Correction
Bias Correction:  88%|███████ | 21/24 [00:29<00:03,  1.19s/blocks, Layers=['head_singleframe_simplified_model/conv_feature_splitter2_1_output_0']]W0000 00:00:1756433876.119088  534661 loop_optimizer.cc:933] Skipping loop optimization for Merge node with control input: cond/else/_1/cond/StatefulPartitionedCall/head_singleframe_simplified_model_submodel/feature_splitter1/Assert/AssertGuard/branch_executed/_93
Bias Correction: 100%|████████████████████████████| 24/24 [00:32<00:00,  1.37s/blocks, Layers=['head_singleframe_simplified_model/output_layer1']]
[info] Model Optimization Algorithm Bias Correction is done (completion time is 00:00:33.52)
[info] Adaround skipped
[info] Quantization-Aware Fine-Tuning skipped
I0000 00:00:1756433884.336963  534661 gpu_device.cc:2022] Created device /job:localhost/replica:0/task:0/device:GPU:0 with 20950 MB memory:  -> device: 0, name: NVIDIA GeForce RTX 4090, pci bus id: 0000:01:00.0, compute capability: 8.9
I0000 00:00:1756433884.951252  534661 gpu_device.cc:2022] Created device /job:localhost/replica:0/task:0/device:GPU:0 with 20954 MB memory:  -> device: 0, name: NVIDIA GeForce RTX 4090, pci bus id: 0000:01:00.0, compute capability: 8.9
[info] Starting Layer Noise Analysis
Full Quant Analysis: 100%|██████████████████████████████████████████████████████████████████████████████████| 2/2 [00:21<00:00, 10.82s/iterations]
[info] Model Optimization Algorithm Layer Noise Analysis is done (completion time is 00:00:22.82)
[info] Output layers signal-to-noise ratio (SNR): measures the quantization noise (higher is better)
[info]  head_singleframe_simplified_model/output_layer3 SNR:    34.15 dB
[info]  head_singleframe_simplified_model/output_layer1 SNR:    32.54 dB
[info]  head_singleframe_simplified_model/output_layer2 SNR:    29.99 dB
[info] Model Optimization is done
[info] Saved HAR to: /home/ubuntu/ycy/onnx_models/hailo_outputs/head_singleframe_simplified_model_hailo_quantized_model.har
✅ Quantized HAR model saved to: /home/ubuntu/ycy/onnx_models/hailo_outputs/head_singleframe_simplified_model_hailo_quantized_model.har
[info] Loading network parameters
[info] Starting Hailo allocation and compilation flow
[info] Building optimization options for network layers...
[info] Successfully built optimization options - 2s 445ms
[info] Trying to compile the network in a single context
[info] Single context flow failed: Recoverable single context error
[info] Building optimization options for network layers...
[info] Successfully built optimization options - 2s 175ms
[info] Building optimization options for network layers...
[info] Successfully built optimization options - 2s 144ms
[info] Building optimization options for network layers...
[info] Successfully built optimization options - 2s 161ms
[info] Building optimization options for network layers...
[info] Successfully built optimization options - 2s 187ms
[info] Building optimization options for network layers...
[info] Successfully built optimization options - 2s 179ms
[error] Mapping Failed (allocation time: 2s)
No valid partition found

[error] Failed to produce compiled graph
❌ Failed to compile HEF model: Compilation failed: No valid partition found
Traceback (most recent call last):
  File "/home/ubuntu/ycy/projects/mmdet3d_plugin/tools/test/hailosim.py", line 160, in <module>
    compiled_hef = runner.compile()
  File "/home/ubuntu/miniconda3/envs/hailo/lib/python3.10/site-packages/hailo_sdk_client/runner/client_runner.py", line 911, in compile
    return self._compile()
  File "/home/ubuntu/miniconda3/envs/hailo/lib/python3.10/site-packages/hailo_sdk_common/states/states.py", line 16, in wrapped_func
    return func(self, *args, **kwargs)
  File "/home/ubuntu/miniconda3/envs/hailo/lib/python3.10/site-packages/hailo_sdk_client/runner/client_runner.py", line 1128, in _compile
    serialized_hef = self._sdk_backend.compile(fps, self.model_script, mapping_timeout)
  File "/home/ubuntu/miniconda3/envs/hailo/lib/python3.10/site-packages/hailo_sdk_client/sdk_backend/sdk_backend.py", line 1910, in compile
    hef, mapped_graph_file = self._compile(fps, allocator_script, mapping_timeout)
  File "/home/ubuntu/miniconda3/envs/hailo/lib/python3.10/site-packages/hailo_sdk_client/sdk_backend/sdk_backend.py", line 1904, in _compile
    hef, mapped_graph_file, auto_alls = self.hef_full_build(fps, mapping_timeout, model_params, allocator_script)
  File "/home/ubuntu/miniconda3/envs/hailo/lib/python3.10/site-packages/hailo_sdk_client/sdk_backend/sdk_backend.py", line 1880, in hef_full_build
    auto_alls, self._hef_data, self._integrated_graph = allocator.create_mapping_and_full_build_hef(
  File "/home/ubuntu/miniconda3/envs/hailo/lib/python3.10/site-packages/hailo_sdk_client/allocator/hailo_tools_runner.py", line 764, in create_mapping_and_full_build_hef
    self.call_builder(
  File "/home/ubuntu/miniconda3/envs/hailo/lib/python3.10/site-packages/hailo_sdk_client/allocator/hailo_tools_runner.py", line 696, in call_builder
    self.run_builder(network_graph_path, output_path, **kwargs)
  File "/home/ubuntu/miniconda3/envs/hailo/lib/python3.10/site-packages/hailo_sdk_client/allocator/hailo_tools_runner.py", line 570, in run_builder
    raise e.internal_exception("Compilation failed:", hailo_tools_error=compiler_msg) from None
hailo_sdk_client.sdk_backend.sdk_backend_exceptions.BackendAllocatorException: Compilation failed: No valid partition found

Please let me know any ideas you have, thank you very much.