perf(simulation): cache SAM3 text and retain exact perception evidence

This commit is contained in:
DCCONSTRUCTIONS
2026-10-08 18:29:32 +03:00
parent 021b9f427f
commit 9a2ea5fc2e
6 changed files with 174 additions and 2 deletions
+7 -1
View File
@@ -11,7 +11,9 @@ from PIL import Image
import sam3.model_builder as builder
from sam3.model.sam3_image_processor import Sam3Processor
from k1link.simulation.ai_polygon.concept_surfaces import PROMPTS, concept_rasters
from k1link.simulation.ai_polygon.concept_surfaces import (
PROMPTS, FixedConceptTextEncoder, concept_rasters,
)
def load_exact(model, path):
@@ -51,6 +53,10 @@ def main():
or any(type(x) not in (int, float) or not 0 < x < 1
for x in thresholds.values())):
raise ValueError("Invalid concept confidence thresholds")
# Encoding depends only on these fixed prompts and the immutable weights.
# Warmup below populates the bounded cache under the same inference/autocast
# context as live frames. Image features and masks are never cached.
model.backbone.forward_text = FixedConceptTextEncoder(model.backbone.forward_text, "cuda")
processor = Sam3Processor(model, device="cuda", confidence_threshold=min(thresholds.values()))
def infer(rgb):