Fix pooling adapters for Transformers backend (#27338)

Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com>
This commit is contained in:
Harry Mellor
2025-10-23 20:23:55 -07:00
committed by GitHub
parent 70022ffc00
commit 1f9460c4c1
6 changed files with 97 additions and 74 deletions
+11 -16
View File
@@ -793,25 +793,20 @@ class ModelConfig:
cls += "MoE" if self.get_num_experts() > 1 else ""
# Check if the architecture we're wrapping has defaults
runner = None
convert = None
task = None
if defaults := try_match_architecture_defaults(self.architectures[0]):
_, (runner, convert) = defaults
# Overwrite with user-specified values
_, (runner, task) = defaults
# User specified value take precedence
if self.runner != "auto":
runner = self.runner
if self.convert not in {"auto", "none"}:
convert = self.convert
# Fall back to default values if still not set
if runner is None:
runner = "generate"
if convert in {None, "none"}:
convert = "embed"
# Resolve Transformers backend task
if runner == "pooling":
if convert == "embed":
return cls + "EmbeddingModel"
if convert == "classify":
return cls + "ForSequenceClassification"
# Only consider Transformers backend pooling classes if we're wrapping an
# architecture that defaults to pooling. Otherwise, we return the LM class
# and use adapters.
if runner == "pooling" and task in {"embed", "classify"}:
if task == "embed":
cls += "EmbeddingModel"
elif task == "classify":
cls += "ForSequenceClassification"
else:
cls += "ForCausalLM"
return cls