Skip to content
class

PlaceholderObserver

extendsObserverBase
PlaceholderObserver(qscheme: QScheme = per_tensor_affine, qdtype: QDtype = quint8, eps: float = 1e-08)

Carries qdtype / qscheme metadata but collects no statistics.

A pure metadata carrier for the cases where a range cannot — or should not — be calibrated ahead of time. The prototypical use is dynamic quantization, where an activation's (scale, zero_point) is computed at runtime from the actual input of each forward, so estimating a static range during a calibration pass would be meaningless. The observer still needs to advertise the target dtype and scheme to downstream consumers (the convert pass, the quantized module), which is exactly what it records — and nothing more. Its forward is the identity, and because there is no statistic to reduce, calculate_qparams deliberately raises.

When to pick it. Use it wherever qparams are supplied elsewhere or produced later: the activation slot of a dynamic-quant recipe, or a tensor deliberately excluded from static calibration. If the range is fixed and known, use FixedQParamsObserver (whose calculate_qparams returns the constants instead of raising); if the range should be learned from data, use a statistics-collecting observer such as MinMaxObserver or HistogramObserver.

There is no statistic and no reduction — only the recorded metadata; asking for qparams is an error:

calculate_qparams()  ⇒  raise RuntimeError\text{calculate\_qparams}() \;\Rightarrow\; \textbf{raise } \texttt{RuntimeError}

Parameters

qschemeQScheme= per_tensor_affine
Target quantization scheme recorded for downstream consumers.
qdtypeQDtype= quint8
Target quantized dtype recorded for downstream consumers (grid + storage).
epsfloat= 1e-8
Retained for interface symmetry with ObserverBase; unused because no range is ever derived.

Attributes

qschemeQScheme
The recorded target scheme (metadata only).
qdtypeQDtype
The recorded target dtype (metadata only).

Notes

  • No buffers. Unlike the min/max family, this observer registers no running statistic — there is nothing to persist beyond the metadata fields.
  • Identity forward. forward returns x unchanged and gathers nothing.
  • calculate_qparams raises. It throws RuntimeError by design — the qparams are produced at runtime (dynamic quantization) or supplied elsewhere, so there is no stored range to return. Callers must not treat this observer as a static-range source.
  • Relation to NoopObserver — NoopObserver is a named subclass with identical behaviour, used to mark tensors that should pass through untouched.

Examples

>>> import lucid
>>> import lucid.quantization as Q
>>> obs = Q.PlaceholderObserver()
>>> _ = obs(lucid.randn(4, 8))               # identity: observes nothing
>>> try:
...     obs.calculate_qparams()              # no statistic ⇒ raises
... except RuntimeError as e:
...     print("raised")
raised

See Also

Used by 2

Constructors

1
dunder

__init__

→None
__init__(qscheme: QScheme = per_tensor_affine, qdtype: QDtype = quint8, eps: float = 1e-08)

Instance methods

2
fn

calculate_qparams

→tuple[Tensor, Tensor]
calculate_qparams()

Return (scale, zero_point) from the accumulated statistics.

fn

forward

→Tensor
forward(x: Tensor)

Identity — no statistics are gathered.