PlaceholderObserver
ObserverBasePlaceholderObserver(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:
Parameters
Attributes
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.
forwardreturnsxunchanged and gathers nothing. calculate_qparamsraises. It throwsRuntimeErrorby 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—NoopObserveris 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")
raisedSee Also
- lucid.quantization.NoopObserver—Named no-op subclass with the same behaviour.
- lucid.quantization.FixedQParamsObserver—Fixed qparams (returns, does not raise).
- lucid.quantization.MinMaxObserver—Statistics-collecting observer for static ranges.
- lucid.quantization.FakeQuantize—Wraps an observer for QAT.