0ef5fcb1c5
Security / Dependency audit (pip-audit) (push) Has been cancelled
Security / CodeQL (javascript-typescript) (push) Has been cancelled
Security / CodeQL (python) (push) Has been cancelled
Security / Secret scan (gitleaks) (push) Has been cancelled
rust / test (ubuntu) (push) Has been cancelled
rust / simulator e2e (macos-latest) (push) Has been cancelled
rust / simulator e2e (ubuntu-latest) (push) Has been cancelled
rust / simulator e2e (windows-latest) (push) Has been cancelled
rust / wheels (aarch64-apple-darwin) (push) Has been cancelled
rust / wheels (x86_64-unknown-linux-gnu) (push) Has been cancelled
rust / wheels (x86_64-apple-darwin) (push) Has been cancelled
rust / audit (push) Has been cancelled
rust / parity (nightly, allowed to fail during Phase 0) (push) Has been cancelled
CI / commitlint (push) Has been skipped
Dev Containers / validate (.devcontainer/devcontainer.json, default) (push) Failing after 0s
Dev Containers / validate (.devcontainer/memory-stack/devcontainer.json, memory-stack) (push) Failing after 0s
Dev Containers / validate-worktree (push) Failing after 0s
CI / changes (push) Failing after 4s
Deploy Documentation / validate (push) Has been skipped
Deploy Documentation / deploy (push) Failing after 1s
Init Native E2E / init-native (ubuntu-latest, claude) (push) Failing after 1s
Init Native E2E / init-native (ubuntu-latest, codex) (push) Failing after 1s
Install Native E2E / install-native (ubuntu-latest) (push) Failing after 1s
OpenCode Plugin / typecheck + build + test (push) Failing after 1s
Init Native E2E / init-native (ubuntu-latest, copilot) (push) Failing after 1s
Release Please / release-please (push) Failing after 1s
Wrap E2E / docker-wrap-e2e (push) Failing after 1s
Wrap Native E2E / wrap-native (ubuntu-latest) (push) Failing after 1s
Init E2E / docker-init-e2e (push) Failing after 4s
Merge Conflicts / merge-conflicts (push) Failing after 4s
CI / lint (push) Has been cancelled
CI / build-wheel (push) Has been cancelled
CI / build-wheel-windows (push) Has been cancelled
CI / prefetch-model (push) Has been cancelled
CI / test-dashboard-ui (push) Has been cancelled
CI / test (1) (push) Has been cancelled
CI / test (2) (push) Has been cancelled
CI / test (3) (push) Has been cancelled
CI / test (4) (push) Has been cancelled
CI / test-extras (push) Has been cancelled
CI / test-agno (push) Has been cancelled
CI / build (push) Has been cancelled
CI / workflow-validation (push) Has been cancelled
CI / docker-native-e2e (push) Has been cancelled
CI / windows-native-wrapper (push) Has been cancelled
CI / macos-native-wrapper (push) Has been cancelled
Docker / docker-build (map[name:arm64 platform:linux/arm64 runs_on:ubuntu-24.04-arm], map[bake_target:runtime-code-nonroot name:code-nonroot]) (push) Has been cancelled
Docker / docker-build (map[name:arm64 platform:linux/arm64 runs_on:ubuntu-24.04-arm], map[bake_target:runtime-code-slim name:code-slim]) (push) Has been cancelled
Docker / docker-build (map[name:arm64 platform:linux/arm64 runs_on:ubuntu-24.04-arm], map[bake_target:runtime-code-slim-nonroot name:code-slim-nonroot]) (push) Has been cancelled
Docker / docker-build (map[name:arm64 platform:linux/arm64 runs_on:ubuntu-24.04-arm], map[bake_target:runtime-nonroot name:nonroot]) (push) Has been cancelled
Docker / docker-build (map[name:arm64 platform:linux/arm64 runs_on:ubuntu-24.04-arm], map[bake_target:runtime-slim name:slim]) (push) Has been cancelled
Docker / docker-build (map[name:arm64 platform:linux/arm64 runs_on:ubuntu-24.04-arm], map[bake_target:runtime-slim-nonroot name:slim-nonroot]) (push) Has been cancelled
Docker / docker-manifest (map[bake_target:runtime name:]) (push) Has been cancelled
Docker / docker-manifest (map[bake_target:runtime-code name:code]) (push) Has been cancelled
Docker / docker-manifest (map[bake_target:runtime-code-nonroot name:code-nonroot]) (push) Has been cancelled
Docker / docker-manifest (map[bake_target:runtime-code-slim name:code-slim]) (push) Has been cancelled
Docker / docker-manifest (map[bake_target:runtime-code-slim-nonroot name:code-slim-nonroot]) (push) Has been cancelled
Docker / docker-manifest (map[bake_target:runtime-nonroot name:nonroot]) (push) Has been cancelled
Docker / docker-manifest (map[bake_target:runtime-slim name:slim]) (push) Has been cancelled
Docker / docker-manifest (map[bake_target:runtime-slim-nonroot name:slim-nonroot]) (push) Has been cancelled
Docker / docker-build (map[name:amd64 platform:linux/amd64 runs_on:ubuntu-24.04], map[bake_target:runtime name:]) (push) Has been cancelled
Docker / docker-build (map[name:amd64 platform:linux/amd64 runs_on:ubuntu-24.04], map[bake_target:runtime-code name:code]) (push) Has been cancelled
Docker / docker-build (map[name:amd64 platform:linux/amd64 runs_on:ubuntu-24.04], map[bake_target:runtime-code-nonroot name:code-nonroot]) (push) Has been cancelled
Docker / docker-build (map[name:amd64 platform:linux/amd64 runs_on:ubuntu-24.04], map[bake_target:runtime-code-slim name:code-slim]) (push) Has been cancelled
Docker / docker-build (map[name:amd64 platform:linux/amd64 runs_on:ubuntu-24.04], map[bake_target:runtime-code-slim-nonroot name:code-slim-nonroot]) (push) Has been cancelled
Docker / docker-build (map[name:amd64 platform:linux/amd64 runs_on:ubuntu-24.04], map[bake_target:runtime-nonroot name:nonroot]) (push) Has been cancelled
Docker / docker-build (map[name:amd64 platform:linux/amd64 runs_on:ubuntu-24.04], map[bake_target:runtime-slim name:slim]) (push) Has been cancelled
Docker / docker-build (map[name:amd64 platform:linux/amd64 runs_on:ubuntu-24.04], map[bake_target:runtime-slim-nonroot name:slim-nonroot]) (push) Has been cancelled
Docker / docker-build (map[name:arm64 platform:linux/arm64 runs_on:ubuntu-24.04-arm], map[bake_target:runtime name:]) (push) Has been cancelled
Docker / docker-build (map[name:arm64 platform:linux/arm64 runs_on:ubuntu-24.04-arm], map[bake_target:runtime-code name:code]) (push) Has been cancelled
Docker / promote-latest (push) Has been cancelled
Init Native E2E / init-native (macos-latest, claude) (push) Has been cancelled
Init Native E2E / init-native (macos-latest, codex) (push) Has been cancelled
Init Native E2E / init-native (macos-latest, copilot) (push) Has been cancelled
Install Native E2E / install-native (macos-latest) (push) Has been cancelled
Wrap Native E2E / wrap-native (macos-latest) (push) Has been cancelled
146 lines
4.7 KiB
Python
146 lines
4.7 KiB
Python
"""Central configuration for all ML models used in Headroom.
|
|
|
|
This is the SINGLE SOURCE OF TRUTH for model defaults. Change values here
|
|
to switch model variants across the entire codebase.
|
|
|
|
Usage:
|
|
from headroom.models.config import ML_MODEL_DEFAULTS
|
|
|
|
# Get default model name
|
|
model = ML_MODEL_DEFAULTS.sentence_transformer
|
|
|
|
# Or use environment variables to override at runtime:
|
|
# HEADROOM_SENTENCE_TRANSFORMER=intfloat/e5-small-v2
|
|
# HEADROOM_SIGLIP=google/siglip-base-patch16-224
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import os
|
|
from dataclasses import dataclass, field
|
|
|
|
|
|
@dataclass
|
|
class MLModelConfig:
|
|
"""Central configuration for all ML model defaults.
|
|
|
|
All model names are defined here. Components throughout Headroom
|
|
import these defaults, so changing a value here changes it everywhere.
|
|
|
|
Environment variables can override any default:
|
|
- HEADROOM_SENTENCE_TRANSFORMER
|
|
- HEADROOM_SIGLIP
|
|
- HEADROOM_SPACY
|
|
- HEADROOM_TECHNIQUE_ROUTER
|
|
|
|
Attributes:
|
|
sentence_transformer: Model for text embeddings (semantic similarity, memory).
|
|
Default: all-MiniLM-L6-v2 (22M params, 384 dim, ~90MB)
|
|
Alternative: intfloat/e5-small-v2 (33M params, better accuracy)
|
|
|
|
sentence_transformer_dim: Embedding dimension for the sentence transformer.
|
|
Must match the model's output dimension.
|
|
|
|
siglip: Model for image embeddings and analysis.
|
|
Default: google/siglip-base-patch16-224 (~400MB)
|
|
Alternative: google/siglip-so400m-patch14-384 (larger, more accurate)
|
|
|
|
spacy: Model for named entity recognition.
|
|
Default: en_core_web_sm (~40MB)
|
|
Alternative: en_core_web_md (~120MB, more accurate)
|
|
|
|
technique_router: Model for image optimization routing.
|
|
Default: chopratejas/technique-router (~100MB)
|
|
"""
|
|
|
|
# Text Embeddings (SentenceTransformer)
|
|
sentence_transformer: str = field(
|
|
default_factory=lambda: os.environ.get("HEADROOM_SENTENCE_TRANSFORMER", "all-MiniLM-L6-v2")
|
|
)
|
|
sentence_transformer_dim: int = 384
|
|
|
|
# Image Embeddings (SIGLIP)
|
|
siglip: str = field(
|
|
default_factory=lambda: os.environ.get("HEADROOM_SIGLIP", "google/siglip-base-patch16-224")
|
|
)
|
|
|
|
# Named Entity Recognition (spaCy)
|
|
spacy: str = field(default_factory=lambda: os.environ.get("HEADROOM_SPACY", "en_core_web_sm"))
|
|
|
|
# Image Technique Router
|
|
technique_router: str = field(
|
|
default_factory=lambda: os.environ.get(
|
|
"HEADROOM_TECHNIQUE_ROUTER", "chopratejas/technique-router"
|
|
)
|
|
)
|
|
|
|
# Memory estimates in MB (for monitoring)
|
|
_memory_estimates: dict[str, int] = field(
|
|
default_factory=lambda: {
|
|
# Sentence Transformers
|
|
"all-MiniLM-L6-v2": 90,
|
|
"all-mpnet-base-v2": 420,
|
|
"intfloat/e5-small-v2": 130,
|
|
"intfloat/e5-base-v2": 440,
|
|
# SIGLIP
|
|
"google/siglip-base-patch16-224": 400,
|
|
"google/siglip-so400m-patch14-384": 900,
|
|
"google/siglip-large-patch16-384": 1200,
|
|
# spaCy
|
|
"en_core_web_sm": 40,
|
|
"en_core_web_md": 120,
|
|
"en_core_web_lg": 560,
|
|
# Technique Router
|
|
"chopratejas/technique-router": 100,
|
|
}
|
|
)
|
|
|
|
def get_memory_estimate(self, model_name: str) -> int:
|
|
"""Get estimated memory usage for a model in MB.
|
|
|
|
Args:
|
|
model_name: The model identifier.
|
|
|
|
Returns:
|
|
Estimated memory in MB, or 100 if unknown.
|
|
"""
|
|
return self._memory_estimates.get(model_name, 100)
|
|
|
|
def total_memory_estimate(self) -> int:
|
|
"""Get total estimated memory if all configured models are loaded.
|
|
|
|
Returns:
|
|
Total estimated memory in MB.
|
|
"""
|
|
return (
|
|
self.get_memory_estimate(self.sentence_transformer)
|
|
+ self.get_memory_estimate(self.siglip)
|
|
+ self.get_memory_estimate(self.spacy)
|
|
+ self.get_memory_estimate(self.technique_router)
|
|
)
|
|
|
|
|
|
# Singleton instance - import this to get defaults
|
|
ML_MODEL_DEFAULTS = MLModelConfig()
|
|
|
|
|
|
# Convenience accessors for common use cases
|
|
def get_default_embedding_model() -> str:
|
|
"""Get the default sentence transformer model name."""
|
|
return ML_MODEL_DEFAULTS.sentence_transformer
|
|
|
|
|
|
def get_default_embedding_dim() -> int:
|
|
"""Get the default embedding dimension."""
|
|
return ML_MODEL_DEFAULTS.sentence_transformer_dim
|
|
|
|
|
|
def get_default_spacy_model() -> str:
|
|
"""Get the default spaCy model name."""
|
|
return ML_MODEL_DEFAULTS.spacy
|
|
|
|
|
|
def get_default_siglip_model() -> str:
|
|
"""Get the default SIGLIP model name."""
|
|
return ML_MODEL_DEFAULTS.siglip
|