[Model] Migrate FlexOlmo, Olmo3 and Hunyuan V1/VL to the Transformers modeling backend (#53615)

Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com>
Signed-off-by: Cyrus Leung <tlleungac@connect.ust.hk>
Co-authored-by: Xianbao QIAN <xianbao.qian@gmail.com>
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
Co-authored-by: Cyrus Leung <tlleungac@connect.ust.hk>
This commit is contained in:
Harry Mellor
2026-08-24 22:39:05 -07:00
committed by GitHub
co-authored by Xianbao QIAN Claude Opus 5 Cyrus Leung
parent 4f3e255dca
commit 48d7132962
14 changed files with 47 additions and 3028 deletions
@@ -22,7 +22,7 @@ from functools import lru_cache
from itertools import chain
from operator import attrgetter
from pathlib import Path
from typing import TYPE_CHECKING, Literal
from typing import TYPE_CHECKING, Literal, TypeVar
import torch
from torch import nn
@@ -306,6 +306,14 @@ def recursive_replace_linear(
_recursive_replace(model, prefix=prefix)
T = TypeVar("T")
def maybe_per_layer(value: T | list[T], layer_idx: int) -> T:
"""Pick `layer_idx`'s entry from a config field that may be sized per layer."""
return value[layer_idx] if isinstance(value, list) else value
def named_state(module: nn.Module) -> Iterator[tuple[str, torch.Tensor]]:
"""`module`'s own state (i.e. named parameters and buffers)."""
return chain(module.named_parameters(), module.named_buffers())