WeightMapper
Unified weight mapping utility for applying loaded weights to SKaiNET modules.
This object provides format-agnostic weight mapping logic that can be used by any model loader (ONNX, GGUF, SafeTensors, etc.). It supports:
Path-based name matching with automatic normalization
Shape-based fallback matching when names don't match
Debug mode for troubleshooting mapping issues
Example usage:
val tensors: List<WeightTensor<FP32, Float>> = loader.loadWeights(modelFile)
val result = WeightMapper.applyWeights(module, tensors)
WeightMapper.validateAllParametersMapped(result)Functions
Apply weights to a module using name-based matching with shape-based fallback.
Extract the most specific "model.X.Y.Z" pattern from a DSL module path. E.g., "Yolo8/model.22.cv2.0/model.22.cv2.0.0/Conv2d-0" -> "model.22.cv2.0.0"
Check if a weight tensor name matches a DSL layer name. E.g., "model.22.cv2.0.0.conv.weight" matches DSL: "model.22.cv2.0.0"
Normalize a DSL layer name to ONNX-style naming format. DSL uses underscores in some places while ONNX uses dots.
Validate that all module parameters were mapped from weight tensors. Throws IllegalArgumentException if mapping is incomplete.