Skip to content

Commit

Permalink
Added comments to 3 functions across 1 file
Browse files Browse the repository at this point in the history
  • Loading branch information
komment-ai-beta[bot] authored Apr 15, 2024
1 parent 1cd9e2f commit afdc34e
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 44 deletions.
2 changes: 1 addition & 1 deletion .komment/README.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"name":"README","path":"README.md","content":{"raw":{"text":"Last generated: 2024-04-12T10:23:37.336Z\n\nLatest pipeline: [bfd2f251-d61b-4ad8-a732-e815d3824502](/pipeline/bfd2f251-d61b-4ad8-a732-e815d3824502)","type":"md"}}}
{"name":"README","path":"README.md","content":{"raw":{"text":"Last generated: 2024-04-15T13:52:47.661Z\n\nLatest pipeline: [00201da6-0183-49cd-ae2a-8bcd0ee64cfb](/pipeline/00201da6-0183-49cd-ae2a-8bcd0ee64cfb)","type":"md"}}}
2 changes: 1 addition & 1 deletion .komment/quant_modules/learnable_fake_quantize.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"name":"learnable_fake_quantize.py","path":"quant_modules/learnable_fake_quantize.py","content":{"structured":{"description":"","items":[{"id":"ced8ecde-d074-4dc7-b404-872b95b012be","ancestors":[],"type":"function","name":"__init__","location":{"offset":" ","indent":8,"start":29,"insert":40},"code":"def __init__(\r\n self,\r\n observer,\r\n quant_min=0,\r\n quant_max=255,\r\n scale=1.0,\r\n zero_point=0.0,\r\n channel_len=-1,\r\n use_grad_scaling=False,\r\n **observer_kwargs,\r\n ):\r\n super().__init__(\r\n observer=observer,\r\n quant_min=quant_min,\r\n quant_max=quant_max,\r\n scale=scale,\r\n zero_point=zero_point,\r\n channel_len=channel_len,\r\n use_grad_scaling=use_grad_scaling,\r\n **observer_kwargs,\r\n )\r\n delattr(self, \"observer_enabled\")\r\n self.register_buffer(\r\n \"PTQ_observer_enabled\", torch.tensor([0], dtype=torch.uint8)\r\n )\r\n self.observer = self._get_PTQ_forward()\r\n self.transform = self._get_fake_quant_forward()\r\n # The symmetric/affine and grad-scaling/no-grad-scaling forward calls\r\n # do not typically change over the lifetime of the quantization module.\r\n self.symmetric_or_affine = self._get_symmetric_or_affine_forward()\r\n self.grad_scaling = self._get_grad_scaling()","params":[{"name":"observer","value":null,"type":null},{"name":"quant_min","value":"0","type":null},{"name":"quant_max","value":"255","type":null},{"name":"scale","value":"1.0","type":null},{"name":"zero_point","value":"0.0","type":null},{"name":"channel_len","value":"-1","type":null},{"name":"use_grad_scaling","value":"False","type":null}],"returns":false,"skip":false,"length":31,"comment":{"description":"initializes a PyTorch Quantization module, setting up the observer, quantization parameters, and forward calls for symmetric/affine transformation and grad scaling/no-grad scaling.","params":[{"name":"observer","type":"`torch.nn.Module`.","value":null,"description":"observer for the quantized model, which is used to enable or disable the observer during runtime.\n\n\t* `observer`: This is the input observer that is used to compute the gradient of the module's forward pass. It is a PyTorch tensor with shape `(1,)` containing an integer value between 0 and 255.\n\t* `quant_min`: The minimum value of the quantized range. It is an integer parameter passed to the constructor.\n\t* `quant_max`: The maximum value of the quantized range. It is an integer parameter passed to the constructor.\n\t* `scale`: A scaling factor used for computing the gradient of the forward pass. It is a floating-point number parameter passed to the constructor.\n\t* `zero_point`: The zero point of the quantized range. It is an integer parameter passed to the constructor.\n\t* `channel_len`: The length of the channel (i.e., the number of input features). It is a positive integer parameter passed to the constructor.\n\t* `use_grad_scaling`: A boolean parameter that controls whether gradients are scaled during training. It is set to `False` by default.\n"},{"name":"quant_min","type":"int","value":"0","description":"8-bit signed minimum value for the quantized signal."},{"name":"quant_max","type":"int","value":"255","description":"maximum output value for the quantized signal, which determines the range of possible values that the module can produce."},{"name":"scale","type":"float","value":"1.0","description":"scalar factor used to rescale the quantized values during forward propagation, allowing for finer control over the resulting output range."},{"name":"zero_point","type":"float","value":"0.0","description":"0-based offset for the quantized values, which is used to shift the output of the forward pass to align with the range of the target device's data types."},{"name":"channel_len","type":"int","value":"-1","description":"1D length of the output channels of the quantization module, which determines the number of values that can be represented in each channel."},{"name":"use_grad_scaling","type":"bool","value":"False","description":"whether to use gradient scaling during quantization, and it defaults to `False`."}],"returns":null}},{"id":"756b2a21-a7c1-42ab-9f57-1ddd11e01dae","ancestors":[],"type":"function","name":"observe_quant_params","location":{"offset":" ","indent":8,"start":105,"insert":106},"code":"def observe_quant_params(self):\r\n print(f\"_LearnableFakeQuantize Scale: {self.scale.detach()}\")\r\n print(f\"_LearnableFakeQuantize Zero Point: {self.zero_point.detach()}\")","params":[],"returns":false,"skip":false,"length":3,"comment":{"description":"prints the values of the `scale` and `zero_point` attributes of an instance of the `_LearnableFakeQuantize` class.","params":[],"returns":null}},{"id":"8b5dd5dd-265b-42cb-9e4d-f160baa61655","ancestors":[],"type":"function","name":"extra_repr","location":{"offset":" ","indent":8,"start":327,"insert":328},"code":"def extra_repr(self):\r\n return (\r\n \"observer_call={}, transform_call={}, fake_quant_enabled={}, PTQ_observer_enabled={}, \"\r\n \"grad_scaling={}, quant_min={}, quant_max={}, dtype={}, qscheme={}, ch_axis={}, \"\r\n \"scale={}, zero_point={}\".format(\r\n self.observer.__name__,\r\n self.transform.__name__,\r\n self.fake_quant_enabled,\r\n self.PTQ_observer_enabled,\r\n self.use_grad_scaling,\r\n self.activation_post_process.quant_min,\r\n self.activation_post_process.quant_max,\r\n self.dtype,\r\n self.qscheme,\r\n self.ch_axis,\r\n self.scale,\r\n self.zero_point,\r\n )\r\n )","params":[],"returns":true,"skip":false,"length":19,"comment":{"description":"generates a string representation of an instance of the `ABC` class by calling specific attributes and formatting them into a singular string.","params":[],"returns":{"type":"str","description":"a string representing the instance's attributes in a standardized format."}}}]}}}
{"name":"learnable_fake_quantize.py","path":"quant_modules/learnable_fake_quantize.py","content":{"structured":{"description":"","image":"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n<!-- Generated by graphviz version 2.43.0 (0)\n -->\n<!-- Title: EQ.EQ Pages: 1 -->\n<svg width=\"464pt\" height=\"114pt\"\n viewBox=\"0.00 0.00 464.00 113.50\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n<g id=\"graph0\" class=\"graph\" transform=\"scale(1 1) rotate(0) translate(4 109.5)\">\n<title>EQ.EQ</title>\n<!-- Node1 -->\n<g id=\"Node000001\" class=\"node\">\n<title>Node1</title>\n<g id=\"a_Node000001\"><a xlink:title=\" \">\n<polygon fill=\"#999999\" stroke=\"#666666\" points=\"47,-67.5 0,-67.5 0,-48.5 47,-48.5 47,-67.5\"/>\n<text text-anchor=\"middle\" x=\"23.5\" y=\"-55.5\" font-family=\"Helvetica,sans-Serif\" font-size=\"10.00\">EQ.EQ</text>\n</a>\n</g>\n</g>\n<!-- Node2 -->\n<g id=\"Node000002\" class=\"node\">\n<title>Node2</title>\n<g id=\"a_Node000002\"><a xlink:href=\"classfake__quantize_1_1EQFakeQuantize.html\" target=\"_top\" xlink:title=\" \">\n<polygon fill=\"white\" stroke=\"#666666\" points=\"250,-105.5 83,-105.5 83,-86.5 250,-86.5 250,-105.5\"/>\n<text text-anchor=\"middle\" x=\"166.5\" y=\"-93.5\" font-family=\"Helvetica,sans-Serif\" font-size=\"10.00\">fake_quantize.EQFakeQuantize</text>\n</a>\n</g>\n</g>\n<!-- Node1&#45;&gt;Node2 -->\n<g id=\"edge1_Node000001_Node000002\" class=\"edge\">\n<title>Node1&#45;&gt;Node2</title>\n<g id=\"a_edge1_Node000001_Node000002\"><a xlink:title=\" \">\n<path fill=\"none\" stroke=\"#63b8ff\" d=\"M56.98,-66.75C78.89,-72.66 107.77,-80.44 130.24,-86.5\"/>\n<polygon fill=\"#63b8ff\" stroke=\"#63b8ff\" points=\"57.72,-63.33 47.15,-64.11 55.9,-70.09 57.72,-63.33\"/>\n</a>\n</g>\n</g>\n<!-- Node3 -->\n<g id=\"Node000003\" class=\"node\">\n<title>Node3</title>\n<g id=\"a_Node000003\"><a xlink:href=\"classfake__quantize_1_1EQFixedQParamsFakeQuantize.html\" target=\"_top\" xlink:title=\" \">\n<polygon fill=\"white\" stroke=\"#666666\" points=\"456,-92 286,-92 286,-62 456,-62 456,-92\"/>\n<text text-anchor=\"start\" x=\"294\" y=\"-80\" font-family=\"Helvetica,sans-Serif\" font-size=\"10.00\">fake_quantize.EQFixedQParams</text>\n<text text-anchor=\"middle\" x=\"371\" y=\"-69\" font-family=\"Helvetica,sans-Serif\" font-size=\"10.00\">FakeQuantize</text>\n</a>\n</g>\n</g>\n<!-- Node1&#45;&gt;Node3 -->\n<g id=\"edge3_Node000001_Node000003\" class=\"edge\">\n<title>Node1&#45;&gt;Node3</title>\n<g id=\"a_edge3_Node000001_Node000003\"><a xlink:title=\" \">\n<path fill=\"none\" stroke=\"#63b8ff\" d=\"M57.48,-59.81C109.54,-62.68 212.4,-68.33 285.9,-72.37\"/>\n<polygon fill=\"#63b8ff\" stroke=\"#63b8ff\" points=\"57.35,-56.3 47.17,-59.25 56.96,-63.29 57.35,-56.3\"/>\n</a>\n</g>\n</g>\n<!-- Node4 -->\n<g id=\"Node000004\" class=\"node\">\n<title>Node4</title>\n<g id=\"a_Node000004\"><a xlink:href=\"classlearnable__fake__quantize_1_1EQLearnableFakeQuantize.html\" target=\"_top\" xlink:title=\" \">\n<polygon fill=\"white\" stroke=\"#666666\" points=\"238,-30 95,-30 95,0 238,0 238,-30\"/>\n<text text-anchor=\"start\" x=\"103\" y=\"-18\" font-family=\"Helvetica,sans-Serif\" font-size=\"10.00\">learnable_fake_quantize.</text>\n<text text-anchor=\"middle\" x=\"166.5\" y=\"-7\" font-family=\"Helvetica,sans-Serif\" font-size=\"10.00\">EQLearnableFakeQuantize</text>\n</a>\n</g>\n</g>\n<!-- Node1&#45;&gt;Node4 -->\n<g id=\"edge4_Node000001_Node000004\" class=\"edge\">\n<title>Node1&#45;&gt;Node4</title>\n<g id=\"a_edge4_Node000001_Node000004\"><a xlink:title=\" \">\n<path fill=\"none\" stroke=\"#63b8ff\" d=\"M56.94,-48.11C74.53,-42.74 96.64,-36 116.31,-30\"/>\n<polygon fill=\"#63b8ff\" stroke=\"#63b8ff\" points=\"55.7,-44.83 47.15,-51.09 57.74,-51.52 55.7,-44.83\"/>\n</a>\n</g>\n</g>\n<!-- Node2&#45;&gt;Node3 -->\n<g id=\"edge2_Node000002_Node000003\" class=\"edge\">\n<title>Node2&#45;&gt;Node3</title>\n<g id=\"a_edge2_Node000002_Node000003\"><a xlink:title=\" \">\n<path fill=\"none\" stroke=\"#63b8ff\" d=\"M260.19,-87.3C268.78,-86.5 277.46,-85.68 285.97,-84.88\"/>\n<polygon fill=\"#63b8ff\" stroke=\"#63b8ff\" points=\"259.79,-83.83 250.16,-88.24 260.44,-90.8 259.79,-83.83\"/>\n</a>\n</g>\n</g>\n</g>\n</svg>\n","items":[{"id":"4a425ab7-552b-438b-847d-8b33adcae781","ancestors":[],"type":"function","name":"__init__","location":{"offset":" ","indent":8,"start":29,"insert":40},"code":"def __init__(\r\n self,\r\n observer,\r\n quant_min=0,\r\n quant_max=255,\r\n scale=1.0,\r\n zero_point=0.0,\r\n channel_len=-1,\r\n use_grad_scaling=False,\r\n **observer_kwargs,\r\n ):\r\n super().__init__(\r\n observer=observer,\r\n quant_min=quant_min,\r\n quant_max=quant_max,\r\n scale=scale,\r\n zero_point=zero_point,\r\n channel_len=channel_len,\r\n use_grad_scaling=use_grad_scaling,\r\n **observer_kwargs,\r\n )\r\n delattr(self, \"observer_enabled\")\r\n self.register_buffer(\r\n \"PTQ_observer_enabled\", torch.tensor([0], dtype=torch.uint8)\r\n )\r\n self.observer = self._get_PTQ_forward()\r\n self.transform = self._get_fake_quant_forward()\r\n # The symmetric/affine and grad-scaling/no-grad-scaling forward calls\r\n # do not typically change over the lifetime of the quantization module.\r\n self.symmetric_or_affine = self._get_symmetric_or_affine_forward()\r\n self.grad_scaling = self._get_grad_scaling()","params":[{"name":"observer","value":null,"type":null},{"name":"quant_min","value":"0","type":null},{"name":"quant_max","value":"255","type":null},{"name":"scale","value":"1.0","type":null},{"name":"zero_point","value":"0.0","type":null},{"name":"channel_len","value":"-1","type":null},{"name":"use_grad_scaling","value":"False","type":null}],"returns":false,"skip":false,"stripped":"super().__init__(\r\n observer=observer,\r\n quant_min=quant_min,\r\n quant_max=quant_max,\r\n scale=scale,\r\n zero_point=zero_point,\r\n channel_len=channel_len,\r\n use_grad_scaling=use_grad_scaling,\r\n **observer_kwargs,\r\n )\r\n delattr(self, \"observer_enabled\")\r\n self.register_buffer(\r\n \"PTQ_observer_enabled\", torch.tensor([0], dtype=torch.uint8)\r\n )\r\n self.observer = self._get_PTQ_forward()\r\n self.transform = self._get_fake_quant_forward()\r\n # The symmetric/affine and grad-scaling/no-grad-scaling forward calls\r\n # do not typically change over the lifetime of the quantization module.\r\n self.symmetric_or_affine = self._get_symmetric_or_affine_forward()\r\n self.grad_scaling = self._get_grad_scaling()","length":31,"comment":{"description":"initializes a PyTorch Quantization module by setting up observer, quantizer, and transformation buffers, as well as defining the forward calls for symmetric/affine and grad-scaling operations.","params":[{"name":"observer","type":"`torch.nn.Module` or other modules derived from it.","value":null,"description":"observer for the quantized module, which is used to control the behavior of the module and enable/disable certain features such as gradient scaling.\n\n\t* `observer`: This is the input observer, which is an instance of a class derived from `torch.nn.Module`. It contains various attributes and methods that define its behavior and properties.\n\t* `observer_kwargs`: This is a dictionary of keyword arguments passed to the constructor of the `observer` module. These arguments can be used to customize the behavior of the observer.\n\t* `quant_min`: The minimum value for quantization, which is an integer between 0 and 255.\n\t* `quant_max`: The maximum value for quantization, which is also an integer between 0 and 255.\n\t* `scale`: A scalar value that determines the scaling factor for the quantized values.\n\t* `zero_point`: An integer value that represents the offset for the quantized values.\n\t* `channel_len`: The length of the channels in the input data, which can be an integer or a scalar value.\n\t* `use_grad_scaling`: A boolean value that indicates whether gradient scaling should be used during training.\n"},{"name":"quant_min","type":"int","value":"0","description":"0-based index of the minimum allowable value for each pixel in the input image, which is used to set the lower bound of the quantized range."},{"name":"quant_max","type":"int","value":"255","description":"7-bit maximum value that the quantizer can produce for each channel in the forward pass, which limits the range of output values for each channel."},{"name":"scale","type":"float","value":"1.0","description":"1-dimensional scalar factor that multiplies the output of each neuron in the forward pass, which allows for flexible scaling of the quantized activations during inference."},{"name":"zero_point","type":"float","value":"0.0","description":"0-value offset for the scaled pixel values in the Quantized Forward Pass, which helps to map the pixel values to the correct range within the quantized space."},{"name":"channel_len","type":"int","value":"-1","description":"length of the channel or feature vector in the observation."},{"name":"use_grad_scaling","type":"bool","value":"False","description":"use of grad-scaling technique during quantization, which helps to reduce the impact of gradient scaling on the model's performance during training."}],"returns":null}},{"id":"67c77655-942f-4beb-8cb5-70b5a486e1c4","ancestors":[],"type":"function","name":"observe_quant_params","location":{"offset":" ","indent":8,"start":105,"insert":106},"code":"def observe_quant_params(self):\r\n print(f\"_LearnableFakeQuantize Scale: {self.scale.detach()}\")\r\n print(f\"_LearnableFakeQuantize Zero Point: {self.zero_point.detach()}\")","params":[],"returns":false,"skip":false,"stripped":"print(f\"_LearnableFakeQuantize Scale: {self.scale.detach()}\")\r\n print(f\"_LearnableFakeQuantize Zero Point: {self.zero_point.detach()}\")","length":3,"comment":{"description":"prints the learnable fake quantization scale and zero point.","params":[],"returns":null}},{"id":"2a04b3f7-ed86-48dc-885d-47008ec7b5c6","ancestors":[],"type":"function","name":"extra_repr","location":{"offset":" ","indent":8,"start":327,"insert":328},"code":"def extra_repr(self):\r\n return (\r\n \"observer_call={}, transform_call={}, fake_quant_enabled={}, PTQ_observer_enabled={}, \"\r\n \"grad_scaling={}, quant_min={}, quant_max={}, dtype={}, qscheme={}, ch_axis={}, \"\r\n \"scale={}, zero_point={}\".format(\r\n self.observer.__name__,\r\n self.transform.__name__,\r\n self.fake_quant_enabled,\r\n self.PTQ_observer_enabled,\r\n self.use_grad_scaling,\r\n self.activation_post_process.quant_min,\r\n self.activation_post_process.quant_max,\r\n self.dtype,\r\n self.qscheme,\r\n self.ch_axis,\r\n self.scale,\r\n self.zero_point,\r\n )\r\n )","params":[],"returns":true,"skip":false,"stripped":"return (\r\n \"observer_call={}, transform_call={}, fake_quant_enabled={}, PTQ_observer_enabled={}, \"\r\n \"grad_scaling={}, quant_min={}, quant_max={}, dtype={}, qscheme={}, ch_axis={}, \"\r\n \"scale={}, zero_point={}\".format(\r\n self.observer.__name__,\r\n self.transform.__name__,\r\n self.fake_quant_enabled,\r\n self.PTQ_observer_enabled,\r\n self.use_grad_scaling,\r\n self.activation_post_process.quant_min,\r\n self.activation_post_process.quant_max,\r\n self.dtype,\r\n self.qscheme,\r\n self.ch_axis,\r\n self.scale,\r\n self.zero_point,\r\n )\r\n )","length":19,"comment":{"description":"returns a string representation of an instance of the `AbstractPostProcess` class, containing various properties and values of the instance.","params":[],"returns":{"type":"str","description":"a string containing information about the observer, transform, and other properties of an instance of `QuantizedModel`."}}}]}}}
Loading

0 comments on commit afdc34e

Please sign in to comment.