Implement AI Host functionality with model caching and job management

- Added ai_host.py to handle AI tasks with FastAPI integration.
- Introduced HostState and ModelCache classes for managing client connections and model loading.
- Implemented job submission and cancellation endpoints in the AI host.
- Enhanced tests for AI host functionality, including client tracking and job cancellation.
- Updated existing tests to accommodate changes in the operator and command structure.
- Refactored runtime commands to use request-based architecture instead of command-line arguments.
- Improved model loading logic to handle CUDA memory management and reuse models efficiently.
This commit is contained in:
2026-08-04 07:35:40 +08:00
parent d694980da7
commit 838af0ee96
16 changed files with 2112 additions and 225 deletions

View File

@@ -29,6 +29,7 @@ class BootstrapRuntimeTest(unittest.TestCase):
args = SimpleNamespace(
uv="uv",
runtime_dir=str(runtime_dir),
models_dir=str(root / "models"),
backend="cu128",
da3_commit="test-commit",
ben2_commit="test-ben2-commit",
@@ -67,13 +68,48 @@ class BootstrapRuntimeTest(unittest.TestCase):
self.assertTrue(
any("test-ben2-commit" in str(value) for value in ben2_command)
)
check_command = commands[-1]
host_command = next(
command
for command in commands
if f"fastapi=={bootstrap.FASTAPI_VERSION}" in command
)
self.assertIn(f"uvicorn=={bootstrap.UVICORN_VERSION}", host_command)
check_command = next(
command
for command in commands
if any("import torch;" in str(value) for value in command)
)
self.assertTrue(
any(
"from ben2 import BEN_Base" in str(value)
for value in check_command
)
)
self.assertTrue(
any("import fastapi, uvicorn" in str(value) for value in check_command)
)
default_downloads = [
command
for command in commands
if any(
repository in command
for repository in (
"depth-anything/DA3-SMALL",
"depth-anything/DA3-BASE",
"PramaLLC/BEN2",
)
)
]
self.assertEqual(len(default_downloads), 3)
ben2_download = next(
command
for command in default_downloads
if "PramaLLC/BEN2" in command
)
self.assertEqual(
ben2_download[-1],
'["config.json", "model.safetensors"]',
)
if __name__ == "__main__":