<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Gokul Krishna on Medium]]></title>
        <description><![CDATA[Stories by Gokul Krishna on Medium]]></description>
        <link>https://medium.com/@debuggerpaco?source=rss-dcb7a91e9522------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*_sKggu8y9MKhVEeFyC-WoQ.jpeg</url>
            <title>Stories by Gokul Krishna on Medium</title>
            <link>https://medium.com/@debuggerpaco?source=rss-dcb7a91e9522------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 10:50:55 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@debuggerpaco/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com" rel="hub"/>
        <item>
            <title><![CDATA[Why I Check Exact Replay When Debugging INT8 Models]]></title>
            <link>https://debuggerpaco.medium.com/why-i-check-exact-replay-when-debugging-int8-models-67e67cffc0e6?source=rss-dcb7a91e9522------2</link>
            <guid isPermaLink="false">https://medium.com/p/67e67cffc0e6</guid>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[model-quantization]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <dc:creator><![CDATA[Gokul Krishna]]></dc:creator>
            <pubDate>Thu, 22 Oct 2026 13:01:33 GMT</pubDate>
            <atom:updated>2026-10-22T13:01:33.464Z</atom:updated>
            <content:encoded><![CDATA[<p>While testing an INT8 model, I found that the original classifier and its replay gave different output codes for the same image. Both predicted horse, but the horse output code was 16 in the original and 17 in the replay.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vAxoVJdDFeG1BhZz029giQ.png" /></figure><p>Replay here means running the final classifier separately on the same saved integer features, with the same weights, integer bias, scales and zero points. I used its float-output mode and then applied the original output quantization.</p><p>I was using the replay to study the final quantization step. Adding that step back needed to reproduce the original codes exactly, so I had to investigate the mismatch before continuing.</p><p>INT8 stores values as integers from −128 to 127. The scale sets the size of each step, and the zero point tells us which code represents zero.</p><p>In the integer reference, we subtract the zero points, multiply matching feature and weight codes, add the products, and add the integer bias. The scales then convert this sum into a score.</p><p>For the horse output, the products summed to 1,427,687. Adding the integer bias of −1,191 gave 1,426,496. Python arithmetic, NumPy arithmetic, and a separate integer operation in the runtime all agreed. The reference sums stayed within INT32 limits.</p><p>Using the stored scales without intermediate rounding gave a reference score of about 8.7308830035. The float-output replay gave about 8.7308835983. Float32 rounding can produce slightly different scores.</p><p>Quantizing either of these scores using exact division and ties-to-even rounding gives code 17. The small score difference alone does not explain the 16-versus-17 mismatch.</p><p>I chose the four candidate scale calculations before running this diagnostic. In the folded-scale paths, I combined the input and weight scales with division by the output scale to make one multiplier. The output scale was about 0.0904754698, and the zero point was −80.</p><p>Two candidate paths folded the output scale into the multiplier and gave 96.5 with float32 rounding. Since 96.5 is halfway between 96 and 97, ties-to-even chose 96. Adding the zero point of −80 gave code 16.</p><p>Dividing the float-output score by the output scale gave an exact reference slightly above 96.5. Rounding gave 97, and adding the zero point of −80 gave code 17. The standalone quantizer returned 17 for the same score.</p><figure><img alt="Four rows compare the horse output: S2 lies just below the midpoint, S3 and S4 lie exactly on it, the exact scaled reference lies just above it, and the observed float-output score after exact division lies farther above it. The upper two rows give code 16; the lower two give code 17." src="https://cdn-images-1.medium.com/max/1024/1*MUkDrF8kw_MVUB4huXT72w.png" /><figcaption>Figure 1. Horse output for test image 4054. Zero on the horizontal axis means 96.5 before integer rounding and zero-point addition; distances are in millionths of a code unit. The upper two rows give code 16; the lower two give code 17. These are reference or candidate calculations, not hidden values observed inside the fused classifier. Both recorded paths still predict horse.</figcaption></figure><p>I used one existing INT8 version of a CIFAR-10 MobileNetV2 x0.5 model. I checked 32 inputs used for earlier controls, plus test image 4054, chosen because its replay had failed. Each input had ten class outputs, giving 33 inputs and 330 output codes.</p><p>Repeating each path reproduced its own saved outputs exactly for all 33 inputs; the known 16-versus-17 difference between the paths remained. Turning runtime profiling on or off also left the outputs unchanged. I checked the integer sums with Python integers, NumPy int64 arithmetic, and the runtime’s MatMulInteger operation followed by an INT32 bias addition. The runtime combines the original classifier’s arithmetic into one operation, called a fused operator.</p><p>I ran the checks locally on an Apple M1 Pro Mac with 16 GB RAM, using Python 3.12.13, NumPy 2.5.4 and ONNX Runtime 1.31.0. The model ran on the CPU, processing one input at a time. I used sequential execution, with the intra-operation and inter-operation thread counts both set to one, and enabled all graph optimizations.</p><p>Both folded-scale candidates matched all 330 original output codes. A third candidate, which applied the input and weight scales one after the other, also matched all 330 codes.</p><p>Different calculation orders can give the same rounded codes. Several paths matched the original output codes, but without the fused classifier’s intermediate values, we couldn’t confirm its calculation order.</p><p>The float-output replay runs the classifier in a different output mode; it does not show a hidden score from inside the original quantized calculation. The separate integer check also does not reveal the fused classifier’s internal sum. I chose the horse image because its replay had failed. These checks help investigate that failure, but do not measure overall accuracy or show that other models and computers will behave the same way.</p><p>Different scale calculations and rounding reproduced the one-code difference using the same checked integer sum. Both paths still predicted horse, but we couldn’t confirm the fused classifier’s calculation order.</p><p>The larger study needed the replay to reproduce the original codes after adding final quantization back. Since it didn’t always match, we need to revise the reference and validate it across all models and inputs before continuing.</p><p>The <a href="https://github.com/gokul-debugger/INT8ExactReplay/tree/v1.0.0">companion code and recorded data</a> are available in a separate public repository. Readers can regenerate the arithmetic tables and figure from saved numerical observations, and optionally rerun the standalone output quantizer. The bundle does not include the full model, images, captured features or weight matrices, so it cannot rerun the original classifier or independently reconstruct its integer dot products. The <a href="https://github.com/gokul-debugger/INT8ExactReplay/blob/v1.0.0/METHODS.md">methods</a> and <a href="https://github.com/gokul-debugger/INT8ExactReplay/blob/v1.0.0/LIMITATIONS.md">limitations</a> explain that boundary. A <a href="https://github.com/gokul-debugger/INT8ExactReplay/releases/tag/v1.0.0">versioned ZIP and checksum</a> are included in the release.</p><p>When an experiment relies on exact replay, we need to check the output codes. Small differences in arithmetic precision can change them even when the predicted class stays the same.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=67e67cffc0e6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Bubble Sort’s Early Exit: Why Input Order Matters]]></title>
            <link>https://debuggerpaco.medium.com/bubble-sorts-early-exit-why-input-order-matters-d3db0a0079e2?source=rss-dcb7a91e9522------2</link>
            <guid isPermaLink="false">https://medium.com/p/d3db0a0079e2</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[data-structures]]></category>
            <category><![CDATA[computer-science]]></category>
            <category><![CDATA[algorithms]]></category>
            <dc:creator><![CDATA[Gokul Krishna]]></dc:creator>
            <pubDate>Mon, 19 Oct 2026 18:15:41 GMT</pubDate>
            <atom:updated>2026-10-19T18:15:41.411Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rcrqR4cU03uKxfXUCjVYGg.png" /></figure><p>Bubble Sort is usually considered slow, but it doesn’t always need every pass. If the list is already sorted, an early exit lets it stop after just one pass.</p><p>For a list like [1, 2, 3], Bubble Sort makes two comparisons and no swaps. Since no swaps happened during the pass, it knows the list is sorted and stops.</p><p>The code uses a flag called swapped to keep track of swaps during each pass. If no swaps happen, it stops instead of starting another pass.</p><pre>def bubble_sort(values):<br>    data = list(values)<br>    for end in range(len(data) - 1, 0, -1):<br>        swapped = False<br>        for i in range(end):<br>            if data[i] &gt; data[i + 1]:<br>                data[i], data[i + 1] = data[i + 1], data[i]<br>                swapped = True<br>        if not swapped:<br>            break<br>    return data</pre><p>The swapped flag resets to False at the start of each pass so it only tracks swaps in that pass. Otherwise, a swap from an earlier pass could prevent the early exit.</p><p>For [2, 1, 3], the first pass sorts the list, but swapped is still True because a swap happened. The second pass makes no swaps, so it stops.</p><p>For an already sorted list of n values, where n ≥ 2, Bubble Sort makes n - 1 comparisons in one pass. As the list gets larger, the number of comparisons grows in proportion to its size.</p><p>For a list of distinct values in reverse order, Bubble Sort makes n - 1 comparisons, then n - 2, and so on. This adds up to n(n - 1)/2, so the work grows quadratically.</p><h3>Comparing input orders</h3><p>To see how input order affects performance, I compared shuffled, sorted, and reversed versions of the same values. Keeping the values the same made order the main difference between them.</p><p>I used ten sets of distinct integers at each size: 100, 500, 1,000 and 2,000. Each set was tested in all three orders. A second dataset used a different random seed, and I reported the datasets separately.</p><p>At 2,000 values, sorted input had the lowest median time in Dataset 1 (0.06917 ms), followed by shuffled input (112.7 ms), while reversed input took the longest (140.6 ms). This shows how input order affected this implementation in these measurements.</p><figure><img alt="Two panels show Bubble Sort median time per call for 2,000 matched values in two datasets. Sorted inputs take about 0.07 ms, shuffled inputs about 113 ms, and reversed inputs about 141 ms. Time is on a logarithmic axis. Whiskers show descriptive interquartile ranges across ten input sets." src="https://cdn-images-1.medium.com/max/1024/1*59PkT-uTWVKeWwnyMNmwoQ.png" /><figcaption>Figure 1. Median time per call in milliseconds on a logarithmic axis: 0.1 to 1 ms takes the same horizontal space as 1 to 10 ms. Whiskers show descriptive interquartile ranges across ten input sets, not confidence intervals. Some whiskers are hidden by the markers.</figcaption></figure><p>Sorted input makes no swaps in the first pass, so the early exit stops it. Reversed input keeps making swaps and needs every pass to finish sorting.</p><p>I measured each input in five batches and divided each batch’s time by its number of sort calls. I took the median of those five per-call averages for each input, then the median across ten inputs.</p><p>I ran the experiment on one computer using warmed-up calls, with input copying included in the timing. The setup was CPython 3.12.13 on an M1 Pro with 16 GB RAM. The exact times may differ on another machine or with background activity.</p><p>The original benchmark included four other sorting methods in its timing schedule. The public rerun script runs only Bubble Sort, so it does not recreate that full schedule.</p><p>Big-O helps explain how work grows, but benchmark results also depend on the exact implementation, input order, and measurement conditions. Looking at these together makes the results easier to interpret.</p><p><a href="https://github.com/gokul-debugger/bubble-sort-early-exit/releases/tag/v1.0.1">Code, data and versioned download</a> · <a href="https://github.com/gokul-debugger/bubble-sort-early-exit/blob/v1.0.1/METHODS.md">Full methods and limitations</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d3db0a0079e2" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>