Skip to content

Commit e9e595c

Browse files
committed
di_engine_decoder: subclass the kit Engine (synchronize/runtime/close)
1 parent 0d7756d commit e9e595c

1 file changed

Lines changed: 29 additions & 2 deletions

File tree

‎benchmarks/di_engine_decoder.py‎

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,32 @@ def _text(x: Any) -> str:
3232
return x if isinstance(x, str) else json.dumps(x, ensure_ascii=False, separators=(",", ":"))
3333

3434

35-
class VonDecoderEngine:
35+
try: # the kit's base class carries synchronize/runtime/close; fall back so unit tests import without the kit
36+
from decision_index.engines.base import Engine as _Base
37+
except ImportError: # pragma: no cover
38+
class _Base: # type: ignore[no-redef]
39+
def __init__(self, **options: Any) -> None:
40+
self.options = options
41+
42+
def runtime(self) -> Dict[str, Any]:
43+
return {}
44+
45+
def synchronize(self) -> None:
46+
pass
47+
48+
def close(self) -> None:
49+
pass
50+
51+
52+
class VonDecoderEngine(_Base):
3653
"""One joint forward pass per request: every question of the request is packed into the same sequence."""
3754

3855
name = "von-2-nano"
3956
latency = ("In-process request wall time including prompt construction; excludes model loading. "
4057
"GPU bf16 autocast when available, one request at a time.")
4158

4259
def __init__(self, **options: Any) -> None:
43-
self.options = options
60+
super().__init__(**options)
4461
self._checkpoint_dir = options.get("checkpoint_dir") or "checkpoints/von-2-nano"
4562
self._device_name = options.get("device")
4663
# 0 = the checkpoint's training max_length. Longer values run the trunk past its trained positions.
@@ -70,6 +87,16 @@ def _load(self) -> None:
7087
self.provenance["base_model"] = self._cfg.get("base_model_id", self.provenance["base_model"])
7188
self.provenance["max_length"] = self._max_length
7289

90+
def synchronize(self) -> None:
91+
if self._model is not None and self._device.type == "cuda":
92+
import torch
93+
torch.cuda.synchronize(self._device)
94+
95+
def runtime(self) -> Dict[str, Any]:
96+
import torch
97+
return {"torch": torch.__version__, "device": str(getattr(self, "_device", "unloaded")),
98+
"max_length": self._max_length}
99+
73100
def warmup(self) -> None:
74101
self._load()
75102
self("The color is red.", {"c": {"type": "choice", "instructions": "Which color is named?",

0 commit comments

Comments
 (0)