invoke= — How the Model Is Called
invoke= is optional. If inference can be run as model(input), you do not need to write it.
Declare it when inference goes through a different method, requires fixed arguments, or when inputs and outputs are wrapped in a container.
from ml_debugger.spec import Invoke
spec = ModelSpec(
labels=LabelSchema(n_class=3, ground_truth=gt),
invoke=Invoke(method="forward_test", kwargs={"rescale": True}),
output=...,
)
Invoke fields
| Field | Default | Contents |
|---|---|---|
method |
"__call__" |
The method inference goes through. The default is model(input) |
unpack_input |
False |
True expands the input container into method(**input) |
kwargs |
{} |
Arguments always passed on the call. Values may be markers (FromCall(), NMSScoreThresh(), …) |
container |
None |
The container format wrapping inputs / outputs. "mmdet3d" unwraps mmcv's DataContainer |
Declaration patterns
| Calling convention | Declaration |
|---|---|
| Inference goes through another method | Invoke(method="forward_test") |
| Several input arguments, expanded as keywords | Invoke(unpack_input=True, kwargs={...}) |
| A fixed argument is always required | Invoke(kwargs={"return_loss": False}) |
| An argument that varies per call must reach the model | Invoke(kwargs={"temperature": FromCall()}) |
| Thresholds arrive as inference arguments | Invoke(kwargs={"conf": NMSScoreThresh(), "iou": NMSIouThresh(), "max_det": NMSMaxDet()}) |
Inputs / outputs are wrapped in an mmcv DataContainer |
Invoke(container="mmdet3d") |
from ml_debugger.spec import FromCall, Invoke, NMSIouThresh, NMSMaxDet, NMSScoreThresh
Forwarding per-call arguments: FromCall
Placing FromCall() in kwargs makes the same-named kwarg you pass to tracer(...) flow through
to the model.
spec = ModelSpec(
labels=LabelSchema(n_class=3, ground_truth=gt),
invoke=Invoke(kwargs={"temperature": FromCall()}),
output=...,
)
tracer = ObjectDetectionTracer(model, spec=spec, model_name="m", version_name="v1")
tracer(images, ground_truth, input_ids=[...], temperature=0.7) # temperature reaches the model
FromCall("other_name")forwards a differently named kwarg.FromCall(default=...)supplies a default when the kwarg is absent.- Any Tracer kwarg not declared as
FromCalldoes not reach the model; it is recorded as metadata in the inference log (see Additional Fields).
Models that take thresholds as inference arguments
For models that receive NMS thresholds as call arguments rather than attributes, put placeholders in
kwargs. Each inference then receives the threshold in effect at that moment.
invoke=Invoke(kwargs={
"conf": NMSScoreThresh(default=0.25),
"iou": NMSIouThresh(),
"max_det": NMSMaxDet(),
})
The threshold values themselves come from the Tracer / Logger / DataFilter arguments
(score_thresh / iou_thresh / max_detections_per_image).
If the thresholds live in model attributes, declare them on
postprocess=NMS(...) instead.
Example: a BEV / mmdet3d model (3D)
Three quirks — "inference goes through forward_test with kwargs", "the values to read live in the
head output, not the return value", and "inputs and outputs are wrapped in a DataContainer" —
are all absorbed declaratively.
from ml_debugger.spec import FromCall, HeadHook, Invoke, LabelSchema, ModelSpec, RawOutputSchema, TopK
from ml_debugger.spec import schema as S
from ml_debugger.training import ObjectDetection3DTracer
spec = ModelSpec(
labels=LabelSchema(
n_class=10,
ground_truth=S.BatchAxis[
S.Dict(
gt_boxes=S.DetAxis[S.Coords3D(layout="standard_7")],
gt_labels=S.DetAxis[S.LabelId(0)],
)
],
),
# the raw output lives in the head, not in the return value
raw_output=RawOutputSchema(
S.Dict(
all_cls_scores=S.Axis("layer", take=-1)[
S.DetAxis[S.ClassConfs(activation="sigmoid", background="none")]
],
all_bbox_preds=S.Axis("layer", take=-1)[
S.DetAxis[S.Coords3D("mmdet3d_logdim")]
],
),
hook=HeadHook("pts_bbox_head"),
),
postprocess=TopK(max_num=300, score_thresh=0.05, topk_mode="flatten"),
# calling convention: model.forward_test(**input_dict, return_loss=False, rescale=True, ...)
invoke=Invoke(
method="forward_test", # call inference through forward_test
unpack_input=True, # expand into forward_test(**input_dict)
kwargs={
"return_loss": False, # always-present literals
"rescale": True,
"temperature": FromCall(),
},
container="mmdet3d", # unwrap DataContainer(.data) for inputs and GT
),
)
tracer = ObjectDetection3DTracer(model, spec=spec, model_name="my_bev", version_name="v1")
tracer(input_dict, ground_truth, input_ids=[...], temperature=0.7)
Temporal state
Temporal state such as prev_bev / scene_token stays under the model's own forward_test
management. MLdebugger only forwards kwargs and captures values through hooks.
Related pages
- raw_output= — reading the raw output from a head or layer
- postprocess= — reading NMS thresholds from model attributes