AlienChen/Storage / pCoMole /flow_matching /utils /categorical_sampler.py
AlienChen's picture
download
raw
615 Bytes
# Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
#
# This source code is licensed under the CC-by-NC license found in the
# LICENSE file in the root directory of this source tree.
import torch
from torch import Tensor
def categorical(probs: Tensor) -> Tensor:
r"""Categorical sampler according to weights in the last dimension of ``probs`` using :func:`torch.multinomial`.
Args:
probs (Tensor): probabilities.
Returns:
Tensor: Samples.
"""
return torch.multinomial(probs.flatten(0, -2), 1, replacement=True).view(
*probs.shape[:-1]
)

Xet Storage Details

Size:
615 Bytes
·
Xet hash:
716672dff8b0a3046eb828d95ab4868ff3a9cd8130f4d0b37443828054affb4d

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.