Better typing for model.config (#39132)

* Apply to all models config annotation

* Update modular to preserve order

* Apply modular

* fix define docstring

* fix dinov2 consistency (docs<->modular)

* fix InstructBlipVideoForConditionalGeneration docs<->modular consistency

* fixup

* remove duplicate code

* Delete config_class attribute from the modeling code

* Add config_class attribute in base model

* Update init sub class

* Deprecated models update

* Update new models

* Fix remote code BC issue

* fixup

* fixing more corner cases

* fix new models

* add test

* modular docs update

* fix comment a bit

* fix for py3.9
This commit is contained in:
Pavel Iakubovskii
2025-07-16 13:50:35 +01:00
committed by GitHub
parent 4b258454a7
commit cc24b0378e
391 changed files with 630 additions and 585 deletions

View File

@@ -945,30 +945,20 @@ def replace_class_node(
new_class_docstring = modular_docstring if len(modular_docstring) > 0 else original_modeling_docstring
# Compute new class attributes
original_modeling_class_attributes = {
node.body[0].targets[0].target.value: node
for node in original_modeling_node.body.body
if m.matches(node, m.SimpleStatementLine(body=[m.Assign()]))
}
original_modeling_class_attributes.update(
{
node.body[0].target.value: node
for node in original_modeling_node.body.body
if m.matches(node, m.SimpleStatementLine(body=[m.AnnAssign()]))
}
)
modular_class_attributes = {
node.body[0].targets[0].target.value: node
for node in modular_class_node.body.body
if m.matches(node, m.SimpleStatementLine(body=[m.Assign()]))
}
modular_class_attributes.update(
{
node.body[0].target.value: node
for node in modular_class_node.body.body
if m.matches(node, m.SimpleStatementLine(body=[m.AnnAssign()]))
}
)
original_modeling_class_attributes = {}
for node in original_modeling_node.body.body:
if m.matches(node, m.SimpleStatementLine(body=[m.Assign()])):
original_modeling_class_attributes[node.body[0].targets[0].target.value] = node
elif m.matches(node, m.SimpleStatementLine(body=[m.AnnAssign()])):
original_modeling_class_attributes[node.body[0].target.value] = node
modular_class_attributes = {}
for node in modular_class_node.body.body:
if m.matches(node, m.SimpleStatementLine(body=[m.Assign()])):
modular_class_attributes[node.body[0].targets[0].target.value] = node
elif m.matches(node, m.SimpleStatementLine(body=[m.AnnAssign()])):
modular_class_attributes[node.body[0].target.value] = node
# Use all original modeling attributes, and potentially override some with values in the modular
new_class_attributes = list({**original_modeling_class_attributes, **modular_class_attributes}.values())