refactor: 设计模式优化 inference 模块导入结构
- 新建 cache.py:SlotAllocator 对象池 + PrefixCacheManager - 新建 sampling.py:Temperature/TopK/TopP 可组合策略 - TaskStatus 改用 Enum,GenerationParams 值对象模式 - _STOP 移至 cache.py,解除 engine→scheduler 轻量耦合 - 更新测试导入路径,ruff 格式检查通过
This commit is contained in:
@@ -1,25 +1,46 @@
|
||||
"""Inference module for continuous batching."""
|
||||
"""Inference module for continuous batching.
|
||||
|
||||
Layers:
|
||||
- engine.py: Facade (InferenceEngine), Value Object (GenerationParams, GenerationRequest)
|
||||
- scheduler.py: Continuous-batching loop, Task state machine, TaskStatus enum
|
||||
- cache.py: Object Pool (SlotAllocator), PrefixCacheManager
|
||||
- sampling.py: Strategy pattern (TemperatureStrategy, TopKStrategy, TopPStrategy)
|
||||
- server.py: FastAPI HTTP server (OpenAI-compatible endpoints)
|
||||
"""
|
||||
|
||||
from astrai.inference.engine import (
|
||||
GenerationParams,
|
||||
GenerationRequest,
|
||||
InferenceEngine,
|
||||
)
|
||||
from astrai.inference.sampling import (
|
||||
BaseSamplingStrategy,
|
||||
SamplingPipeline,
|
||||
TemperatureStrategy,
|
||||
TopKStrategy,
|
||||
TopPStrategy,
|
||||
apply_sampling_strategies,
|
||||
)
|
||||
from astrai.inference.scheduler import (
|
||||
InferenceScheduler,
|
||||
Task,
|
||||
TaskStatus,
|
||||
apply_sampling_strategies,
|
||||
)
|
||||
|
||||
__all__ = [
|
||||
# Engine
|
||||
# Engine / Requests
|
||||
"InferenceEngine",
|
||||
"GenerationRequest",
|
||||
"GenerationParams",
|
||||
# Scheduler
|
||||
"InferenceScheduler",
|
||||
"Task",
|
||||
"TaskStatus",
|
||||
# Request
|
||||
"GenerationRequest",
|
||||
# Sampling
|
||||
# Sampling (Strategy pattern)
|
||||
"apply_sampling_strategies",
|
||||
"BaseSamplingStrategy",
|
||||
"TemperatureStrategy",
|
||||
"TopKStrategy",
|
||||
"TopPStrategy",
|
||||
"SamplingPipeline",
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user