Spaces:
Build error
Build error
Download postprocessing/mmaudio/utils/tensor_utils.py from fatslappa/Wan2GP_Demo: direct link, hf CLI and curl.
- Browser
- Download file 510 Bytes
-
https://huggingface.co/spaces/fatslappa/Wan2GP_Demo/resolve/main/postprocessing/mmaudio/utils/tensor_utils.py
- Command line
-
hf download hf://spaces/fatslappa/Wan2GP_Demo/postprocessing/mmaudio/utils/tensor_utils.py
-
curl -L -o tensor_utils.py https://huggingface.co/spaces/fatslappa/Wan2GP_Demo/resolve/main/postprocessing/mmaudio/utils/tensor_utils.py
510 Bytes
| import torch | |
| def distribute_into_histogram(loss: torch.Tensor, | |
| t: torch.Tensor, | |
| num_bins: int = 25) -> tuple[torch.Tensor, torch.Tensor]: | |
| loss = loss.detach().flatten() | |
| t = t.detach().flatten() | |
| t = (t * num_bins).long() | |
| hist = torch.zeros(num_bins, device=loss.device) | |
| count = torch.zeros(num_bins, device=loss.device) | |
| hist.scatter_add_(0, t, loss) | |
| count.scatter_add_(0, t, torch.ones_like(loss)) | |
| return hist, count | |