@@ -30,6 +30,14 @@ def convert_backend(
3030 If True, export .pt2/.pte models with per-atom virial correction.
3131 This adds ~2.5x inference cost. Default False. Silently ignored
3232 (with a warning) for backends that don't support the flag.
33+
34+ Notes
35+ -----
36+ Backend conversion preserves an explicit ``lower_input_kind`` reported by
37+ the source serializer. Sources without this metadata retain the target's
38+ automatic lower selection for backward compatibility. A target backend
39+ that cannot represent an explicit non-dense lower is rejected rather than
40+ silently changing the model function.
3341 """
3442 inp_backend : Backend = Backend .detect_backend_by_model (INPUT )()
3543 out_backend : Backend = Backend .detect_backend_by_model (OUTPUT )()
@@ -40,8 +48,21 @@ def convert_backend(
4048
4149 sig = inspect .signature (out_hook )
4250 hook_kwargs : dict [str , Any ] = {}
51+ lower_input_kind = data .get ("lower_input_kind" )
4352 if "lower_kind" in sig .parameters :
44- hook_kwargs ["lower_kind" ] = "auto"
53+ hook_kwargs ["lower_kind" ] = (
54+ lower_input_kind if lower_input_kind is not None else "auto"
55+ )
56+ elif (
57+ lower_input_kind not in (None , "auto" , "nlist" )
58+ and not out_backend .preserves_lower_input_kind
59+ ):
60+ raise ValueError (
61+ f"Cannot preserve lower_input_kind { lower_input_kind !r} when "
62+ f"converting to output backend { out_backend .name !r} : its "
63+ "deserializer does not accept a lower_kind. Retrain or freeze the "
64+ "model with that backend instead of converting this artifact."
65+ )
4566 if "do_atomic_virial" in sig .parameters :
4667 hook_kwargs ["do_atomic_virial" ] = atomic_virial
4768 elif atomic_virial :
0 commit comments