multinomial(input: Tensor, num_samples: int, replacement: bool = False, generator: _C_engine.Generator | None = None)Draw num_samples indices from the categorical distribution defined by input.
Non-differentiable — gradients of input are not propagated
through the sampling step. Pass an explicit generator for an
isolated PRNG stream; without one, draws come from Lucid's
manual_seed-controlled default Philox generator. The draws
are made on input's device.
With replacement, each draw inverts the cumulative weights at a
uniform sample. Without replacement, the categories are ranked by
log-weight plus Gumbel noise and the first num_samples are kept,
which has the same law as drawing one at a time and removing each
pick.
Parameters
inputTensorProbability weights. 1-D
(K,) for a single categorical
distribution, or 2-D (B, K) for a batch of B
distributions. Weights are renormalised internally; they need
not sum to 1.num_samplesintNumber of draws per distribution.
replacementbool= FalseWhen
True each draw is independent. When False
(default) each chosen index is removed before the next draw
within the same row.Override Lucid's default Philox generator with an isolated
stream.
Returns
TensorInteger tensor. Shape (num_samples,) for 1-D input,
(B, num_samples) for 2-D input.