[BUG] why zero++ need number of weights be a multiple of 8.
AssertionError: Qantized weight requires the number of weights be a multiple of 8. Yet 2305 cannot be divided by 8*2305
Hi @QingruiSun. It is a requirement by our quantization CUDA kernel to achieve the maximal throughput. You can get around it by changing the way the weight buffer is created in zero-3 to make it a multiple of 8 and then narrow it afterward
Thanks for your answer, but i can't understand it. Is it exist one simple solution to solve it and i can use quantized model parameter and gradient communication.
Hi @QingruiSun. Unfortunately, there is no simple way to get around this. Either to patch the CUDA kernel or to patch the way DeepSpeed creates and uses the parameter buffer.
Hi @HeyangQin. I also met the problem when I set zero_quantized_weights=true, I want to know how to patch the way DeepSpeed creates to use this?
afterward
Hi @QingruiSun. It is a requirement by our quantization CUDA kernel to achieve the maximal throughput. You can get around it by changing the way the weight buffer is created in zero-3 to make it a multiple of 8 and then narrow it afterward
Hi, I tried to modify the code in parition_parameters.py and I had modify the function CUDAQuantizer.quantize as follow:
def quantize(self, param, groups=None):
remainder = param.numel() % 8
if remainder != 0:
padding_size = 8 - remainder
padding = torch.zeros(padding_size, device=param.device, dtype=param.dtype)
if not hasattr(param, 'original_size'):
param.original_size = param.numel()
param = torch.cat([param, padding])
if groups is None:
try:
groups = self.group_size_cache[param.numel()]
except KeyError:
groups = math.ceil(param.numel() / self.target_group_size)
while groups < param.numel():
if param.numel() % (8 * groups) == 0:
break
groups += 1
while True:
if param.numel() % (8 * groups * 2) == 0 and param.numel(
) / groups > self.target_group_size: #hard limit of 16k group_size
groups *= 2
else:
break
assert (
param.numel() % (8 * groups) == 0
), f"Qantized weight requires the number of weights be a multiple of 8. Yet {param.numel()} cannot be divided by 8*{groups}"
assert (param.numel() / groups < 16000), f"{param.numel()} / {groups} is larger than 16k"
assert param.numel(
) > groups, f"Adaptive grouping algorithm cannot find a group size for input tensor of size {param.numel()}"
self.group_size_cache[param.numel()] = groups
return self.quantizer_cuda_module.quantize(param.to(get_accelerator().device_name()), groups, 8,
self.quantizer_cuda_module.Symmetric)
but I cannot find a right position to narrow the param object, leading to the error: RuntimeError: output tensor size must be equal to world_size times input tensor size. So in which position can I narrow the param?