def forward(self, x): # self.cnt += 1 # if self.cnt==1000: #import ipdb as pdb; pdb.set_trace() # if self.config["quantization"].lower() == "bnn": # Wb = quant.bnn_sign(self.weight/self.H)*self.H # elif self.config["quantization"].lower() == "int": # Wb = quant.int_nn(self.weight, self.config["weight_i_width"]) # elif self.config["quantization"].lower() == "fixed": # Wb = quant.fixed_nn(self.weight, self.config["weight_i_width"], self.config["weight_f_width"]) # elif self.config["quantization"].lower() == "ternary": # Wb = quant.ternary_q(self.weight) # else: # Wb = self.weight if (self.freezeq): Wb = quant.fixed_nn(self.weight, self.config["save_weight_i_width"], self.config["save_weight_f_width"]) elif (self.config["quantization"].lower() == "fixed"): Wb = quant.fixed_nn(self.weight, self.config["weight_i_width"], self.config["weight_f_width"]) else: Wb = self.weight return F.conv2d(x, Wb, self.bias, self.stride, self.padding, self.dilation, self.groups)
def forward(self, x): if (self.freezeq): return quant.fixed_nn(x, self.config["save_activation_i_width"], self.config["save_activation_f_width"]) elif (self.config["quantization"].lower() == "fixed"): return quant.fixed_nn(x, self.config["activation_i_width"], self.config["activation_f_width"]) else: return x
def forward(self, x): # self.cnt += 1 # if self.cnt==1000: #import ipdb as pdb; pdb.set_trace() if self.config["quantization"].lower() == "bnn": Wb = quant.bnn_sign(self.weight/self.H)*self.H return quant.bnn_sign(F.conv2d(x, Wb, self.bias, self.stride, self.padding, self.dilation, self.groups)) elif self.config["quantization"].lower() == "int": Wb = quant.int_nn(self.weight, self.config["weight_i_width"]) return quant.int_nn(F.conv2d(x, Wb, self.bias, self.stride, self.padding, self.dilation, self.groups), self.config["activation_i_width"]) elif self.config["quantization"].lower() == "fixed": Wb = quant.fixed_nn(self.weight, self.config["weight_i_width"], self.config["weight_f_width"], "weight") return quant.fixed_nn(F.conv2d(x, Wb, self.bias, self.stride, self.padding, self.dilation, self.groups), self.config["activation_i_width"], self.config["activation_f_width"], "activation") else: Wb = self.weight return F.conv2d(x, Wb, self.bias, self.stride, self.padding, self.dilation, self.groups)
def forward(self, input): #import ipdb as pdb; pdb.set_trace() # if self.config["quantization"] == "BNN": # Wb = quant.bnn_sign(self.weight/self.H)*self.H # return quant.bnn_sign(F.linear(input, Wb, self.bias)) # elif self.config["quantization"] == "INT": # Wb = quant.int_nn(self.weight, self.config["weight_i_width"], self.config["weight_f_width"]) # return quant.int_nn(F.linear(input, Wb, self.bias), self.config["activation_i_width"], self.config["activation_f_width"]) # else: # Wb = self.weight # return F.linear(input, Wb, self.bias) if (self.freezeq): Wb = quant.fixed_nn(self.weight, self.config["save_weight_i_width"], self.config["save_weight_f_width"]) elif (self.config["quantization"].lower() == "fixed"): Wb = quant.fixed_nn(self.weight, self.config["weight_i_width"], self.config["weight_f_width"]) else: Wb = self.weight return F.linear(input, Wb, self.bias)
def forward(self, x): #import ipdb as pdb; pdb.set_trace() if self.config["quantization"].lower() == "int": return quant.int_nn(x, self.config["activation_i_width"]) elif self.config["quantization"].lower() == "fixed": return quant.fixed_nn(x, self.config["activation_i_width"], self.config["activation_f_width"]) elif self.config["quantization"].lower() == "bnn": # import ipdb as pdb; pdb.set_trace() return quant.bnn_sign(x) else: return x