refactor: simplify BaseFactory and separate ModelFactory from AutoModel

- Extract _resolve_base_type and _validate_component as module-level helpers
- Replace ForwardRef._evaluate private API with eval in module namespace
- Remove broad except Exception in __init_subclass__, _component_base always set
- Replace direct _entries mutation in strategy.py with register() call form
- Remove dead TOKENIZER_CLASSES registry from AutoTokenizer
- Extract ModelFactory(BaseFactory[nn.Module]) as pure factory
- AutoModel now inherits only nn.Module, no factory state
- Move @AutoModel.register to @ModelFactory.register in transformer.py and encoder.py
This commit is contained in:
2026-07-30 09:38:20 +08:00
parent 22cf798d81
commit fc47319240
8 changed files with 59 additions and 65 deletions
+3 -3
View File
@@ -7,7 +7,7 @@ import safetensors.torch as st
import torch
from astrai.config.model_config import EncoderConfig
from astrai.model.automodel import AutoModel
from astrai.model.automodel import ModelFactory
from astrai.model.encoder import EmbeddingEncoder
from tests.helpers import TINY_CONFIG, assert_state_dicts_equal
@@ -69,8 +69,8 @@ def test_encoder_normalize(device):
def test_encoder_register():
assert AutoModel.is_registered("embedding")
cls = AutoModel.get_component_class("embedding")
assert ModelFactory.is_registered("embedding")
cls = ModelFactory.get_component_class("embedding")
assert cls is EmbeddingEncoder