Team Ai
Datasetpublic

willychan21/ParallelKernelBench_Problems

ParallelKernelBench (benchmark) Reference problems for ParallelKernelBench: a benchmark for LLM-generated multi-GPU CUDA kernels. This dataset contains 87 reference implementations in reference/ and the input tensor specification in utils/input_output_tensors.py. Files Path Description data/problems.parquet One row per problem (tabular access) reference/*.py Reference solution() implementations utils/input_output_tensors.py Input/output tensor… See the full description on the dataset page: https://huggingface.co/datasets/willychan21/ParallelKernelBench_Problems.

sourceHugging Faceapache-2.0updated 5mo agoView on Hugging Face
0likes146downloads
53_fp8_allgather_params.py40 linesDownload Raw Back to reference
1from __future__ import annotations2 3import torch4import torch.distributed as dist5from torch import Tensor6 7_FP8_E4M3_MAX = 448.08 9 10@torch.no_grad()11def _update_amax_history(amax_history: Tensor, cur_abs_max: Tensor) -> Tensor:12    out = torch.roll(amax_history, shifts=-1, dims=0)13    out[-1] = cur_abs_max.to(dtype=out.dtype)14    return out15 16 17@torch.no_grad()18def _fp8_round_trip_bf16(x: Tensor, scale: Tensor) -> Tensor:19    xf = x.float()20    qs = xf / scale21    q = qs.to(torch.float8_e4m3fn)22    return (q.float() * scale).to(dtype=x.dtype)23 24 25@torch.no_grad()26def solution(flat_param_shard: Tensor, amax_history: Tensor) -> tuple[Tensor, Tensor]:27    world_size = dist.get_world_size()28    p = flat_param_shard.numel()29 30    cur_abs_max = flat_param_shard.abs().max().to(torch.float32)31    updated_hist = _update_amax_history(amax_history, cur_abs_max)32 33    scale = updated_hist.max().clamp(min=1e-12).to(torch.float32) / _FP8_E4M3_MAX34    recon = _fp8_round_trip_bf16(flat_param_shard, scale)35 36    full = torch.empty(world_size * p, dtype=flat_param_shard.dtype, device=flat_param_shard.device)37    dist.all_gather_into_tensor(full, recon.contiguous())38 39    return full, updated_hist40