Skip to content

Commit 60f1abe

Browse files
refactor(hf): merge an override into the section's own dict, with no fallback
A section read from either config type has its dict in the data being merged: PretrainedConfig.to_dict serializes every sub-config the config holds, and RawConfigShim wraps only the dicts it holds. The `or {}` fallback was reached only by a section a config class computes in a property, as transformers' PeAudioVideoConfig does, and there the whole-section write it produced was refused at the re-init ("property ... has no setter"); such an override now fails at the merge, naming the section. _with_overrides takes the two config types it is handed.
1 parent 9c635a1 commit 60f1abe

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

  • python/freetoken/utils

‎python/freetoken/utils/hf.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,12 +234,12 @@ def _load_hf_config(model_path: str) -> Any:
234234
return config
235235

236236

237-
def _with_overrides(config: Any, data: dict, overrides: Mapping[str, Any]) -> dict:
237+
def _with_overrides(config: PretrainedConfig | RawConfigShim, data: dict, overrides: Mapping[str, Any]) -> dict:
238238
merged = dict(data)
239239
for key, value in overrides.items():
240240
section = getattr(config, key, None)
241241
if isinstance(value, Mapping) and isinstance(section, (PretrainedConfig, RawConfigShim)):
242-
merged[key] = _with_overrides(section, merged.get(key) or {}, value)
242+
merged[key] = _with_overrides(section, merged[key], value)
243243
else:
244244
merged[key] = copy.deepcopy(value)
245245
return merged

0 commit comments

Comments
 (0)