Skip to content

Commit 90e7ca9

Browse files
yy-code-nvclaude
andcommitted
Restore _to_safe_string in LazyConfig.save_yaml, plus minor VLM/transformers tweaks
- lazy_config/lazy.py: re-add _to_safe_string so callable _target_ values are emitted as importable dotted paths in config.yaml. Without this, save_yaml's fallback `str(value)` produced "<class '...'>" / "<function ... at 0x...>" strings that break downstream consumers like export_model. - configs/base/defaults/vlm.py: add VLMConfig.safetensors_path for loading a safetensors checkpoint from a different folder than model_name. - utils/vfm/monkey_patch.py: loosen _EXPECTED_TRANSFORMERS_VERSION from exact "4.57.1" to "4.57." prefix so patch-version bumps don't trip the guard. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent c92dddf commit 90e7ca9

3 files changed

Lines changed: 26 additions & 3 deletions

File tree

cosmos_framework/configs/base/defaults/vlm.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,9 @@ class VLMConfig:
136136
# HuggingFace model identifier or local path. Drives AutoConfig + AutoModel selection.
137137
model_name: str = ""
138138

139+
# Safetensor path for model for load a safetensor from different folder
140+
safetensors_path: str = ""
141+
139142
# Optional pretrained-weights overlay (separate from the AutoModel structural
140143
# init driven by model_name).
141144
pretrained_weights: PretrainedWeightsConfig = PretrainedWeightsConfig()

cosmos_framework/utils/lazy_config/lazy.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,26 @@ def is_serializable(item):
321321
except Exception as e:
322322
return False
323323

324+
# For classes / functions / bound methods we want the importable dotted
325+
# path, not `repr(obj)` — the latter yields strings like
326+
# `<class 'cosmos.X'>` or `<function f at 0x…>` which break any
327+
# downstream consumer that calls hydra.utils.instantiate on the loaded
328+
# YAML (e.g. cosmos.scripts.export_model).
329+
from cosmos_framework.utils.lazy_config.registry import convert_target_to_string
330+
331+
def _to_safe_string(value):
332+
# Preserve primitives — `str(True)` is the literal string `"True"`,
333+
# which yaml then quotes and downstream consumers parse as a string
334+
# instead of the original bool/int/float.
335+
if isinstance(value, (bool, int, float, str)) or value is None:
336+
return value
337+
try:
338+
if callable(value):
339+
return convert_target_to_string(value)
340+
except Exception:
341+
pass
342+
return str(value)
343+
324344
# Function to convert unserializable items to strings
325345
def serialize_config(config):
326346
if isinstance(config, DictConfig):
@@ -338,14 +358,14 @@ def serialize_config(config):
338358
serialize_config(value)
339359
else:
340360
if not is_serializable(value) and value is not None:
341-
config[key] = str(value)
361+
config[key] = _to_safe_string(value)
342362
elif isinstance(config, ListConfig):
343363
for i, item in enumerate(config):
344364
if isinstance(item, (DictConfig, ListConfig)):
345365
serialize_config(item)
346366
else:
347367
if not is_serializable(item) and item is not None:
348-
config[i] = str(item)
368+
config[i] = _to_safe_string(item)
349369
else:
350370
raise NotImplementedError("Input config must be a DictConfig or ListConfig.")
351371
return config

cosmos_framework/utils/vfm/monkey_patch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
from cosmos_framework.utils import log
1515

16-
_EXPECTED_TRANSFORMERS_VERSION = "4.57.1"
16+
_EXPECTED_TRANSFORMERS_VERSION = "4.57."
1717

1818

1919
def patch_qwen3_vl_forward(model):

0 commit comments

Comments
 (0)