IMPORTANT: To view this page as Markdown, append `.md` to the URL (e.g. /get-started.md). For the complete documentation index, see llms.txt.
Skip to main content
For the complete documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /get-started.md).

Python class

EagerUsageValidator

EagerUsageValidator​

class max.pipelines.EagerUsageValidator(*, enabled=True, label='')

source

Bases: object

A scope that tracks production-unsafe API usages.

Reports:

  1. Eager ops that ran without being fused into a compiled graph.
  2. Graph breaks between compiled graphs.
  3. Compiled outputs that were materialized and never read.
  4. Device-to-host transfers that were not bulk transferred.
from max.experimental.validation import EagerUsageValidator

with EagerUsageValidator():
    ...

To mark where unsafe API usage is deliberate, use escape hatches. Example:

from max.pipelines.modeling.eager_validation import eager_validator

with eager_validator.allow_eager(reason="input batching, off hot path"):
    ...

Parameters:

  • enabled (bool) – When False the scope does nothing at all, so a caller can construct one unconditionally from a config flag.
  • label (str) – Names the scope in warnings, for example, "initialization".

allow_device_transfer()​

allow_device_transfer(*, reason)

source

Opts in to device-to-host transfers for the duration of the block.

Prefer one bulk transfer inside such a block over a transfer per element.

Parameters:

reason (str) – Why the host needs this data.

Return type:

Iterator[None]

allow_eager()​

allow_eager(*, reason)

source

Opts in to eager execution for the duration of the block.

Parameters:

reason (str) – Why eager execution is the right call here. Recorded for the reader, not consulted by the validator.

Return type:

Iterator[None]

discard_output()​

discard_output(output, *, reason)

source

Marks compiled-model outputs as intentionally unread.

Parameters:

  • output (Any) – A tensor or buffer, or any nesting of tuples, lists and dicts holding the outputs to excuse.
  • reason (str) – Why the graph produces an output nothing reads.

Return type:

None

enabled​

property enabled: bool

source

Whether this validator is enabled.

enter()​

enter()

source

Starts validating. Prefer the context manager form.

Return type:

EagerUsageValidator

exit()​

exit(exc_type=None, exc=None, tb=None)

source

Stops validating and reports what the scope saw.

Parameters:

Return type:

None

graph_break()​

graph_break(*, reason)

source

Marks the block as an expected boundary between compiled graphs.

Parameters:

reason (str) – Why the model is compiled in pieces here.

Return type:

Iterator[None]