"""Offline activation-weighted block-scale search for NVFP4 weights.""" import torch import triton import triton.language as tl @triton.jit def _round(v): a=tl.abs(v) code=(a>.25).to(tl.int32)+(a>=.75)+(a>1.25)+(a>=1.75)+(a>2.5)+(a>=3.5)+(a>5.) val=tl.where(code<4,code*.5,tl.where(code==4,2.,tl.where(code==5,3.,tl.where(code==6,4.,6.)))) return code|tl.where(v<0,8,0),val*tl.where(v<0,-1.,1.) @triton.jit def _quant(W,H,G,Q,S,COUNT:tl.constexpr,K:tl.constexpr,SEARCH:tl.constexpr,B:tl.constexpr): b=tl.program_id(0)*B+tl.arange(0,B) i=tl.arange(0,16) w=tl.load(W+b[:,None]*16+i[None,:],b[:,None]