[docs]classBatchNorm2d(torch.nn.BatchNorm2d):r"""This is the quantized version of :class:`~torch.nn.BatchNorm2d`. """def__init__(self,num_features,eps=1e-5,momentum=0.1,device=None,dtype=None)->None:factory_kwargs={'device':device,'dtype':dtype}super(BatchNorm2d,self).__init__(num_features,**factory_kwargs)self.eps=epsself.scale=1.0self.zero_point=0defforward(self,input):returntorch.ops.quantized.batch_norm2d(input,self.weight,self.bias,self.running_mean,self.running_var,self.eps,self.scale,self.zero_point)def_get_name(self):return'QuantizedBatchNorm2d'@classmethoddeffrom_float(cls,mod):activation_post_process=mod.activation_post_processiftype(mod)==nni.BNReLU2d:mod=mod[0]scale,zero_point=activation_post_process.calculate_qparams()new_mod=cls(mod.num_features,mod.eps)new_mod.weight=mod.weightnew_mod.bias=mod.biasnew_mod.running_mean=mod.running_meannew_mod.running_var=mod.running_varnew_mod.scale=float(scale)new_mod.zero_point=int(zero_point)returnnew_mod
# TODO: dedup with BatchNorm2d
[docs]classBatchNorm3d(torch.nn.BatchNorm3d):r"""This is the quantized version of :class:`~torch.nn.BatchNorm3d`. """def__init__(self,num_features,eps=1e-5,momentum=0.1,device=None,dtype=None):factory_kwargs={'device':device,'dtype':dtype}super(BatchNorm3d,self).__init__(num_features,**factory_kwargs)self.eps=epsself.scale=1.0self.zero_point=0defforward(self,input):returntorch.ops.quantized.batch_norm3d(input,self.weight,self.bias,self.running_mean,self.running_var,self.eps,self.scale,self.zero_point)def_get_name(self):return'QuantizedBatchNorm3d'@classmethoddeffrom_float(cls,mod):activation_post_process=mod.activation_post_processiftype(mod)==nni.BNReLU3d:mod=mod[0]scale,zero_point=activation_post_process.calculate_qparams()new_mod=cls(mod.num_features,mod.eps)new_mod.weight=mod.weightnew_mod.bias=mod.biasnew_mod.running_mean=mod.running_meannew_mod.running_var=mod.running_varnew_mod.scale=float(scale)new_mod.zero_point=int(zero_point)returnnew_mod
Docs
Access comprehensive developer documentation for PyTorch
To analyze traffic and optimize your experience, we serve cookies on this site. By clicking or navigating, you agree to allow our usage of cookies. As the current maintainers of this site, Facebook’s Cookies Policy applies. Learn more, including about available controls: Cookies Policy.