<?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 rahularyansharma on Medium]]></title>
        <description><![CDATA[Stories by rahularyansharma on Medium]]></description>
        <link>https://medium.com/@rahularyan786?source=rss-ebee31f452d4------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*IEXE9DANSP3swcjg.jpg</url>
            <title>Stories by rahularyansharma on Medium</title>
            <link>https://medium.com/@rahularyan786?source=rss-ebee31f452d4------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 23:04:11 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@rahularyan786/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[How to integrated GLM 5.2 in Visual Studio Code]]></title>
            <link>https://medium.com/@rahularyan786/how-to-integrated-glm-5-2-in-visual-studio-code-1b6c204dd2b3?source=rss-ebee31f452d4------2</link>
            <guid isPermaLink="false">https://medium.com/p/1b6c204dd2b3</guid>
            <category><![CDATA[glm5-2]]></category>
            <category><![CDATA[glm]]></category>
            <category><![CDATA[coding-agents]]></category>
            <category><![CDATA[open-source]]></category>
            <dc:creator><![CDATA[rahularyansharma]]></dc:creator>
            <pubDate>Thu, 18 Jun 2026 05:23:56 GMT</pubDate>
            <atom:updated>2026-06-18T05:23:56.776Z</atom:updated>
            <content:encoded><![CDATA[<p>To use z.ai (Zhipu AI / GLM models) as a coding agent in Visual Studio Code, you have two main options.</p><p>The first is using their official extension (CodeGeeX), and the second is using the Zhipu API with a powerful open-source agentic extension like Continue.dev or Cline (recommended for true “agentic” behavior).</p><p>Here is how to set up both methods:</p><p><strong>Method 1: Using the Official CodeGeeX Extension<br></strong>CodeGeeX is the official VS Code extension built by Zhipu AI. It provides autocomplete, chat, and basic agent capabilities using their GLM-4 models.</p><p>1.Install the Extension:<br>Open VS Code and go to the Extensions view (Ctrl+Shift+X or Cmd+Shift+X on Mac).<br>Search for CodeGeeX and install it.<br>2. Sign In:<br>Once installed, click the CodeGeeX icon in your sidebar.<br>Click Sign In and log in using your Z.ai/CodeGeeX account (or create one if you don’t have it).<br>3. Use as an Agent:<br>Open the CodeGeeX chat panel.<br>You can ask it to generate code, explain code, write tests, or refactor.<br>It has a feature called “Auto-Run” where it can directly apply changes to your files.</p><p><strong>Method 2: Using the Zhipu API with Continue.dev (Recommended for Advanced Agents)</strong><br>If you want a more powerful, customizable coding agent that can read multiple files, run terminal commands, and write code autonomously, you should use the Z.ai API combined with an extension like Continue.dev or Cline.</p><p>Here is how to set it up using Continue.dev:</p><p>1.Get your Z.ai API Key:<br>Go to the Zhipu AI Open Platform (open.bigmodel.cn).<br>Sign up and navigate to the API Keys section to generate a new key.<br>2. Install Continue.dev:<br>In VS Code Extensions, search for Continue (by ContinueDev) and install it.<br>3. Configure Continue to use Z.ai:<br>Click the Continue icon in your sidebar.<br>Click the gear icon (Settings) at the bottom right of the Continue panel to open your config.json file.<br>Add Z.ai as a custom provider. The Z.ai API is OpenAI-compatible. Your config should look like this:</p><blockquote>{<br> “models”: [<br> {<br> “title”: “Z.ai GLM-4”,<br> “provider”: “openai”,<br> “model”: “glm-4”,<br> “apiKey”: “YOUR_ZHIPU_API_KEY_HERE”,<br> “apiBase”: “https://open.bigmodel.cn/api/paas/v4/&quot;<br> }<br> ],<br> “tabAutocompleteModel”: {<br> “title”: “Z.ai GLM-4-Flash”,<br> “provider”: “openai”,<br> “model”: “glm-4-flash”,<br> “apiKey”: “YOUR_ZHIPU_API_KEY_HERE”,<br> “apiBase”: “https://open.bigmodel.cn/api/paas/v4/&quot;<br> }<br>}</blockquote><p>Note: Replace <strong>YOUR_ZHIPU_API_KEY_HERE</strong> with your actual key.</p><p>Use the Agent:<br>In the Continue chat panel, type <a href="http://twitter.com/codebase">@codebase</a> to let the agent read your entire project, or <a href="http://twitter.com/terminal">@terminal</a> to let it see your terminal output.<br>Ask it to do things like: “Create a new Python file that fetches data from an API, and update my package.json to include the required dependencies.”<br>Continue will use the GLM-4 model to plan the steps, write the code, and present the files for you to accept.<br>Which should you choose?<br>Choose Method 1 (CodeGeeX) if you want something that works right out of the box with a Z.ai account without needing to manage API keys or pay per-token.<br>Choose Method 2 (Continue/Cline + API) if you are building complex applications and want an autonomous agent that can edit multiple files at once, execute terminal commands, and debug its own errors.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1b6c204dd2b3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Slash Your Amazon Bedrock Guardrails Costs Without Sacrificing Safety]]></title>
            <link>https://medium.com/@rahularyan786/how-to-slash-your-amazon-bedrock-guardrails-costs-without-sacrificing-safety-f37da71fcc38?source=rss-ebee31f452d4------2</link>
            <guid isPermaLink="false">https://medium.com/p/f37da71fcc38</guid>
            <category><![CDATA[cost]]></category>
            <category><![CDATA[cost-optimization]]></category>
            <category><![CDATA[aws-bedrock-guardrails]]></category>
            <dc:creator><![CDATA[rahularyansharma]]></dc:creator>
            <pubDate>Wed, 10 Jun 2026 03:12:22 GMT</pubDate>
            <atom:updated>2026-06-10T03:12:22.770Z</atom:updated>
            <content:encoded><![CDATA[<p>If you’re building generative AI applications on AWS, especially with Agents or Bedrock, you’ve probably noticed that Guardrails can quietly add up in your monthly bill. The good news? You can keep your applications safe and responsible while dramatically cutting those costs. I’ve been working with Bedrock Guardrails on several projects, and these practical tactics have helped me reduce guardrail expenses by 40–70% in production workloads.</p><h3>Why Guardrails Cost Money in the First Place</h3><p>Amazon Bedrock Guardrails charge based on the text they process (per 1,000 characters) and the specific policies you enable. Every input and output that flows through an active filter adds to the bill. The more policies you turn on and the more content you evaluate, the higher the cost.</p><p>The key is being intentional instead of enabling every filter by default.</p><h3>1. Only Enable What You Actually Need</h3><p>This is the simplest and most effective change.</p><p>Don’t activate every single policy just because it’s available. Most applications only need:</p><ul><li>Content Filters (harmful content)</li><li>Denied Topics (your custom blocked subjects)</li></ul><p>Sensitive Information filters and Contextual Grounding are more expensive and should be used only where truly required (e.g., handling PII in customer service bots).</p><p><strong>Pro tip:</strong> Regex-based filters and word lists are usually free or extremely cheap. Use them aggressively to catch obvious issues before relying on the heavier ML-powered filters.</p><h3>2. Check Input First — Always</h3><p>This single pattern delivers the biggest savings.</p><p>Run ApplyGuardrail on the user’s input <strong>before</strong> sending it to your LLM or Agent. If the input is blocked or flagged, you stop there. This prevents expensive model inference calls on junk or malicious prompts.</p><pre># Pseudocode - do this<br>guardrail_response = bedrock.apply_guardrail(input_text)<br>if guardrail_response[&#39;action&#39;] == &#39;BLOCK&#39;:<br>    return &quot;Sorry, I can&#39;t help with that.&quot;<br>    <br># Only then call the model<br>response = invoke_bedrock_model(...)</pre><p>This approach not only saves guardrail costs on outputs but also dramatically reduces your foundation model token costs.</p><h3>3. Keep Text Volume Low</h3><p>Guardrails charge per text unit (~1,000 characters), so shorter is cheaper.</p><p>Practical ways to reduce volume:</p><ul><li>Summarize long conversation histories instead of sending everything</li><li>Set strict max token limits on model outputs</li><li>Use structured JSON outputs when possible (less fluffy text)</li><li>Break very long responses into smaller chunks for guardrail evaluation</li></ul><h3>4. Choose the Right Guardrail Tier and Strategy</h3><p>Use the <strong>Standard</strong> tier for most production use cases. It often performs better and leverages cross-region inference at no extra cost.</p><p>For high-traffic applications, consider evaluating guardrails in batches for streaming responses rather than character-by-character. This avoids over-processing the same content multiple times.</p><h3>5. Monitor, Measure, and Tune</h3><p>Turn on CloudWatch metrics and guardrail intervention logs. Look at:</p><ul><li>How often each policy is triggering</li><li>Which filters are blocking legitimate traffic (causing retries)</li><li>Actual text units processed per day</li></ul><p>Many teams start with overly strict settings (High strength) and later dial them back to Medium after seeing real usage patterns. This reduces both blocks and costs.</p><h3>6. Additional Smart Habits</h3><ul><li>Use Prompt Caching on the model side (where available) to reduce overall tokens flowing through the system.</li><li>Version your guardrails and test changes thoroughly in a staging environment.</li><li>For very high-scale applications, combine guardrails with lighter upfront validation layers (simple rule engines).</li></ul><h3>Real-World Impact</h3><p>On one recent project, implementing input-first checking + minimal policies dropped our combined guardrail + inference costs by over 60%. The application stayed just as safe — actually safer, because we could afford to run guardrails on every single interaction.</p><h3>Final Thoughts</h3><p>Guardrails are one of the best tools AWS gives us for building responsible AI, but they don’t have to be expensive. Treat them like any other cloud resource: be deliberate, measure everything, and optimize ruthlessly.</p><p>Start small. Pick your top 2–3 practices from this list and implement them this week. You’ll likely see the difference in your next AWS bill.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f37da71fcc38" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Neural Networks From Scratch, One Idea at a Time : Part 8]]></title>
            <link>https://medium.com/@rahularyan786/neural-networks-from-scratch-one-idea-at-a-time-part-8-f1cb9370fc22?source=rss-ebee31f452d4------2</link>
            <guid isPermaLink="false">https://medium.com/p/f1cb9370fc22</guid>
            <category><![CDATA[gradient-descent]]></category>
            <dc:creator><![CDATA[rahularyansharma]]></dc:creator>
            <pubDate>Sat, 06 Jun 2026 13:45:25 GMT</pubDate>
            <atom:updated>2026-06-06T13:45:25.690Z</atom:updated>
            <content:encoded><![CDATA[<h3>Gradient Descent</h3><p>You already invented this pillar when you said <em>“move each weight opposite to its gradient.”</em> Here it is, precisely:</p><blockquote><strong><em>new weight = old weight − (learning rate × gradient)</em></strong></blockquote><p>Every symbol is something you already know:</p><ul><li><strong>old weight</strong> — the current value, e.g. 0.5.</li><li><strong>gradient</strong> — the signed direction-and-strength number from Pillar 7.</li><li><strong>The minus sign</strong> — automates “move opposite the gradient.” Positive gradient → subtract a positive → weight goes down. Negative gradient → subtract a negative → weight goes up. You never have to think about direction; the formula handles it.</li><li><strong>learning rate</strong> — the one new idea: a small positive number (like 0.01) that sets <em>how big a step to take</em>.</li></ul><h3>Why the learning rate matters</h3><p>The gradient gives <em>direction</em>, but a gradient of 1.5 doesn&#39;t mean &quot;move the weight by 1.5&quot; — that could wildly overshoot. The learning rate scales the step.</p><p>Picture walking to the bottom of a foggy valley. You can feel which way the ground slopes (the gradient), but that doesn’t tell you how big a step to take. The learning rate is your <strong>step size</strong>:</p><ul><li>Too <strong>big</strong> → you leap past the bottom and bounce around (or get worse).</li><li>Too <strong>small</strong> → you shuffle one millimeter at a time; training crawls.</li><li>Just right → you walk steadily downhill to the bottom of the loss valley.</li></ul><h3>Worked examples</h3><p>A weight is 0.5, its gradient is +0.8, learning rate 0.01:</p><pre>new = 0.5 - (0.01 × 0.8) = 0.5 - 0.008 = 0.492</pre><p>The gradient was positive (up makes loss worse), so the weight nudged <em>down</em>. Do this for every weight and you’ve completed <strong>one training step</strong>.</p><blockquote><strong><em>Try it yourself:</em></strong><em> (1) weight </em><em>= 2.0, gradient </em><em>= -1.5, learning rate </em><em>= 0.01 (2) weight </em><em>= -0.3, gradient </em><em>= +0.4, learning rate </em><em>= 0.1</em></blockquote><blockquote><strong><em>Answer:</em></strong><em> (1) </em><em>2.0 - (0.01 × -1.5) = 2.0 + 0.015 = 2.015 — negative gradient pushed it </em>up<em>. (2) </em><em>-0.3 - (0.1 × 0.4) = -0.3 - 0.04 = -0.34 — positive gradient pushed it </em>down<em>.</em></blockquote><h3>The Training Loop — putting it all together</h3><p>One training step isn’t enough. To train a network, you wrap pillars 5–8 in a loop and just keep going:</p><ol><li><strong>Forward pass</strong> — push an input through the network, get a prediction. <em>(Pillar 5)</em></li><li><strong>Compute loss</strong> — compare the prediction to the true answer. <em>(Pillar 6)</em></li><li><strong>Compute gradients</strong> — for every weight, figure out which way it should move. <em>(Pillar 7 — backpropagation)</em></li><li><strong>Update weights</strong> — apply new = old − (learning rate × gradient) to every weight. <em>(Pillar 8)</em></li><li><strong>Repeat</strong> with the next input — thousands or millions of times.</li></ol><p>That’s it. That is <strong>the entire training loop.</strong> Every neural network you’ve heard of — image recognizers, language models, game-playing AIs — is trained by some version of this exact loop. The weights start as random garbage, the loss is huge, the output is nonsense. But each pass nudges every weight a tiny bit downhill on the loss valley. After enough iterations, the loss is small, the weights are tuned, and the network makes accurate predictions.</p><h3>The whole story, in one paragraph</h3><blockquote><strong><em>Tensors</em></strong><em> are containers of numbers, indexed by rank-many decisions. A </em><strong><em>neuron</em></strong><em> computes a weighted sum of its inputs (a dot product), adds a </em><strong><em>bias</em></strong><em>, and passes the result through a non-linear </em><strong><em>activation</em></strong><em> like ReLU. Neurons stack into </em><strong><em>layers</em></strong><em>, and layers chain into a network. The </em><strong><em>forward pass</em></strong><em> sends an input through every layer to produce a final output. The </em><strong><em>loss function</em></strong><em> measures how wrong that output is, squaring the error so direction doesn’t matter and big mistakes hurt more. </em><strong><em>Gradients</em></strong><em> — the derivative of the loss with respect to each weight — tell us which direction and how strongly each weight is pushing the loss. </em><strong><em>Gradient descent</em></strong><em> then updates every weight a tiny step opposite its gradient, scaled by the </em><strong><em>learning rate</em></strong><em>. Repeating this loop many times </em>is<em> training.</em></blockquote><p>Every paper, framework, and architecture you’ll meet from here is a variation on these eight pillars.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f1cb9370fc22" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Neural Networks From Scratch, One Idea at a Time : Part 7]]></title>
            <link>https://medium.com/@rahularyan786/neural-networks-from-scratch-one-idea-at-a-time-part-7-a71bc01477b7?source=rss-ebee31f452d4------2</link>
            <guid isPermaLink="false">https://medium.com/p/a71bc01477b7</guid>
            <dc:creator><![CDATA[rahularyansharma]]></dc:creator>
            <pubDate>Wed, 03 Jun 2026 10:28:49 GMT</pubDate>
            <atom:updated>2026-06-03T10:29:15.329Z</atom:updated>
            <content:encoded><![CDATA[<h3>Gradients</h3><p>This is the hardest pillar, so we go slowly and build the idea of a <strong>derivative</strong> from zero — no calculus assumed.</p><p>The question gradients answer is intuitive:</p><blockquote>“For each weight, should I make it a little bigger or a little smaller to make the loss go down — and how much does it matter?”</blockquote><p>That’s the entire problem of learning. The thing that answers it, for every weight, is the <strong>gradient</strong>.</p><h3>Building a derivative from scratch</h3><p>Forget networks. Here’s a black-box function f, with some results:</p><pre>f(3)    = 9<br>f(3.01) = 9.0601</pre><p>When x nudged <em>up</em> by 0.01, the output went <em>up</em> from 9 to 9.0601 — a change of:</p><pre>9.0601 - 9 = 0.0601</pre><p>Now the key idea — it’s just a ratio. The input moved by 0.01, the output moved by 0.0601, so per unit of input movement:</p><pre>output change ÷ input change = 0.0601 ÷ 0.01 = 6.01</pre><p>This number — <strong>how much the output changes per unit of input change</strong> — is the <strong>derivative</strong> of f at x = 3. It packs two pieces of information:</p><ul><li>Its <strong>sign</strong> (positive) → output goes <em>up</em> when input goes up.</li><li>Its <strong>magnitude</strong> (~6) → output responds about 6× as strongly as the input moves.</li></ul><p>That sign-and-strength pair is <em>exactly</em> what we need for a weight: which direction to push it, and how much it matters.</p><blockquote><strong><em>Try it yourself:</em></strong><em> A function </em><em>g has </em><em>g(5) = 20 and </em><em>g(5.01) = 19.98. What&#39;s its derivative at </em><em>x = 5?</em></blockquote><blockquote><strong><em>Answer:</em></strong><em> Output change </em><em>= 19.98 - 20 = -0.02 (negative — it went down). Input change </em><em>= 0.01. Derivative </em><em>= -0.02 ÷ 0.01 = -2. The minus sign says &quot;when input goes up, output goes down&quot;; the </em><em>2 says it changes twice as fast as the input. </em>(Watch the two common slips: keep the negative sign, and divide by 0.01, not 0.1.)</blockquote><h3>Connecting it to the network</h3><p>In a network the function isn’t a mystery box — it’s the <strong>loss</strong>, and the inputs are every weight and bias. For each weight w we ask the identical question: <em>&quot;if I nudge </em><em>w up a tiny bit, does the loss go up or down, and by how much?&quot;</em> The answer is a signed number: the <strong>gradient</strong> of the loss with respect to that weight.</p><p>And here’s the payoff rule:</p><ul><li>gradient <strong>positive</strong> → nudging w up makes loss <em>worse</em>, so to reduce loss, nudge w <strong>down</strong>.</li><li>gradient <strong>negative</strong> → nudging w up makes loss <em>better</em>, so nudge w <strong>up</strong>.</li></ul><p>In both cases: <strong>move each weight in the <em>opposite</em> direction of its gradient.</strong> That single rule is how networks learn.</p><p>A gradient near zero means <em>“nudging this weight barely moves the loss”</em> — the weight is almost irrelevant right now, so it should barely move. Big gradient → big nudge; tiny gradient → tiny nudge. The gradient <strong>automatically</strong> tells the network which weights to focus on — a free prioritization that’s part of why this scales to millions of weights.</p><blockquote><strong><em>Try it yourself:</em></strong><em> Three weights have gradients </em><em>w1 = +0.8, </em><em>w2 = -1.5, </em><em>w3 = +0.001. For each, which way do you nudge to reduce loss? Which matters most, which least?</em></blockquote><blockquote><strong><em>Answer:</em></strong><em> </em><em>w1 down, </em><em>w2 up, </em><em>w3 down (move opposite the sign). </em><em>w2 has the largest magnitude (1.5) so it matters most right now; </em><em>w3 (0.001) matters least — nudging it barely changes the loss.</em></blockquote><h3>A note on backpropagation</h3><p>I deliberately skipped <em>how</em> the network computes a gradient for every weight efficiently — that algorithm is <strong>backpropagation</strong>. The clever part is that it computes all the gradients in essentially one backward pass through the network, going from the loss back through each layer applying the chain rule. Conceptually, you already understand what backprop <em>produces</em>: a signed number for every weight saying “nudge me this way by this much.”</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a71bc01477b7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Neural Networks From Scratch, One Idea at a Time : Part 6]]></title>
            <link>https://medium.com/@rahularyan786/neural-networks-from-scratch-one-idea-at-a-time-part-6-bfe8100fa391?source=rss-ebee31f452d4------2</link>
            <guid isPermaLink="false">https://medium.com/p/bfe8100fa391</guid>
            <category><![CDATA[loss-function]]></category>
            <category><![CDATA[root-mean-square-error]]></category>
            <dc:creator><![CDATA[rahularyansharma]]></dc:creator>
            <pubDate>Wed, 03 Jun 2026 08:04:15 GMT</pubDate>
            <atom:updated>2026-06-03T08:04:15.415Z</atom:updated>
            <content:encoded><![CDATA[<h3>The Loss Function</h3><p>Suppose a network predicts the temperature in a photo as 18.3, and the real answer was 22. How wrong was it?</p><pre>22 - 18.3 = 3.7</pre><p>You just invented the most natural measure of wrongness: <strong>the difference between what the network said and what was true.</strong> That difference is the <strong>error</strong>, and a function that measures it is a <strong>loss function</strong>.</p><h3>Killing the sign</h3><p>But raw subtraction has a problem. Compare:</p><ul><li>predicted 18.3, actual 22 → off by +3.7</li><li>predicted 25, actual 22 → off by -3</li></ul><p>Being off by 3 is being off by 3, whether you guessed too high or too low. <strong>Direction shouldn’t matter, only size.</strong> But raw errors carry signs, and across many examples the positives and negatives could cancel out — making a bad network look perfect.</p><p>The fix: <strong>square</strong> the error (multiply it by itself). Squaring always produces a positive number:</p><ul><li>error +3.7 → (3.7)² = 13.69</li><li>error -3 → (-3)² = 9</li><li>error 0 → 0² = 0 (a perfect prediction has zero loss)</li></ul><p>So the recipe for one prediction’s <strong>squared error</strong> is:</p><blockquote><strong><em>loss = (predicted − actual)²</em></strong></blockquote><h3>A bonus: squaring punishes big mistakes more</h3><ul><li>off by 2 → loss 4</li><li>off by 4 → loss 16</li><li>off by 10 → loss 100</li></ul><p>A 2× bigger error becomes a 4× bigger loss. The loss function isn’t just saying “you’re wrong” — it’s saying <em>“the more wrong you are, the much more you should care.”</em> Exactly the signal you want when teaching a network: focus on your worst mistakes.</p><h3>Mean Squared Error (MSE)</h3><p>In practice a network predicts on <em>many</em> examples and we want one overall score: compute each example’s squared error, then take the <strong>average</strong>. That’s <strong>Mean Squared Error</strong>:</p><blockquote><em>For each example, compute </em><em>(predicted − actual)². Add them all up. Divide by how many examples there were.</em></blockquote><blockquote><strong><em>Try it yourself:</em></strong><em> Compute the squared error for: (1) predicted </em><em>5, actual </em><em>5; (2) predicted </em><em>7, actual </em><em>10; (3) predicted </em><em>12, actual </em><em>8. Then their MSE.</em></blockquote><blockquote><strong><em>Answer:</em></strong><em> </em><em>(5-5)² = 0, </em><em>(7-10)² = 9, </em><em>(12-8)² = 16. MSE = </em><em>(0 + 9 + 16) / 3 = 25/3 ≈ 8.33. </em><strong><em>Lower is better; zero is perfection.</em></strong></blockquote><p>The goal of training is to make this number as small as possible. But knowing the loss is 8.33 doesn&#39;t yet tell the network <em>how to improve</em> — just <em>that</em> it&#39;s wrong. Closing that gap is the next pillar.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bfe8100fa391" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Neural Networks From Scratch, One Idea at a Time : Part 5]]></title>
            <link>https://medium.com/@rahularyan786/neural-networks-from-scratch-one-idea-at-a-time-part-5-5e798804f449?source=rss-ebee31f452d4------2</link>
            <guid isPermaLink="false">https://medium.com/p/5e798804f449</guid>
            <category><![CDATA[the-forward-pass]]></category>
            <dc:creator><![CDATA[rahularyansharma]]></dc:creator>
            <pubDate>Tue, 02 Jun 2026 01:52:58 GMT</pubDate>
            <atom:updated>2026-06-02T01:52:58.305Z</atom:updated>
            <content:encoded><![CDATA[<h3>The Forward Pass</h3><p>A <strong>layer</strong> is simply <em>several neurons all looking at the same inputs at the same time.</em></p><p>Feed in an input vector — say [2, 3]. Instead of one neuron, you have three sitting side by side. All three receive that <em>same</em> [2, 3], but each has its <strong>own private weights and bias</strong>. Each one does the full neuron calculation you&#39;ve mastered and produces <em>its own</em> single number.</p><p>So a layer of 3 neurons produces <strong>3 numbers</strong> — a <strong>vector</strong>, shape (3). (Not (1, 3) — that&#39;s a rank-2 shape describing a different object. Three numbers in a row is rank 1, shape (3).)</p><p>Here’s the beautiful consequence: a layer <strong>takes a vector in and gives a vector out.</strong> So nothing stops you from feeding that output vector into <em>another</em> layer. Vector out → vector in → vector out… <strong>That chain is the neural network</strong>, and pushing an input all the way through it to get a final output is the <strong>forward pass</strong>.</p><p>One practical rule that falls straight out of this: if a layer outputs N numbers, every neuron in the <em>next</em> layer needs exactly N weights — one per incoming number. <strong>The shape of a layer&#39;s output dictates the wiring of the next layer.</strong></p><h3>A complete worked network</h3><ul><li>Input vector: [1, 2]</li><li><strong>Layer 1</strong> (2 neurons, ReLU):</li><li>Neuron A: weights [1, 0], bias 0</li><li>Neuron B: weights [0, 1], bias 1</li><li><strong>Layer 2</strong> (1 neuron, ReLU):</li><li>weights [2, -1], bias 0.5</li></ul><p><strong>Layer 1:</strong></p><pre>Neuron A: ReLU((1×1 + 2×0) + 0) = ReLU(1) = 1<br>Neuron B: ReLU((1×0 + 2×1) + 1) = ReLU(3) = 3<br>Layer 1 output: [1, 3]   (shape (2))</pre><p><strong>Layer 2</strong> (inputs are Layer 1’s output [1, 3]):</p><pre>ReLU((1×2 + 3×(-1)) + 0.5) = ReLU(-1 + 0.5) = ReLU(-0.5) = 0</pre><p><strong>Final output: </strong><strong>0.</strong> That is mechanically what a real network does to make a prediction — the only difference from a giant network is <em>size</em>.</p><p>But notice: those weights like [2, -1] were <strong>made up</strong>. The network produced 0, and we have no idea whether 0 is a good answer or a terrible one — because we never said what the right answer should be. That gap is what the next pillars close.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5e798804f449" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Neural Networks From Scratch, One Idea at a Time : Part 4]]></title>
            <link>https://medium.com/@rahularyan786/neural-networks-from-scratch-one-idea-at-a-time-part-4-26a4e13c4750?source=rss-ebee31f452d4------2</link>
            <guid isPermaLink="false">https://medium.com/p/26a4e13c4750</guid>
            <category><![CDATA[activation-functions]]></category>
            <dc:creator><![CDATA[rahularyansharma]]></dc:creator>
            <pubDate>Mon, 01 Jun 2026 02:48:31 GMT</pubDate>
            <atom:updated>2026-06-01T02:48:31.997Z</atom:updated>
            <content:encoded><![CDATA[<h3>Activation Functions</h3><p>Here’s a limitation that should bother you. A neuron as built so far is <em>purely linear</em> — weighted sum plus bias is just y = mx + c, a straight line.</p><p>Now chain two neurons: neuron 1 produces 2x + 1, neuron 2 does 3 × (that) + 5:</p><pre>3(2x + 1) + 5 = 6x + 8</pre><p>Still a straight line. And it doesn’t matter if you stack 2, 50, or 500 linear neurons — <em>a straight line of a straight line is always still a straight line.</em> A deep network of pure linear neurons collapses down to a single equivalent linear neuron. All that depth buys you <strong>nothing.</strong></p><p>That’s a real problem, because most patterns in the world aren’t straight lines. Consider “output YES when the temperature is between 20°C and 25°C, NO otherwise.” That’s a <em>bump</em> — up, then down. A straight line can only go one direction forever. It physically cannot make a bump.</p><p>So we insert something <em>non-linear</em> between neurons — something that <strong>bends</strong>. That something is the <strong>activation function</strong>:</p><blockquote><strong><em>output = activation( weighted sum + bias )</em></strong></blockquote><h3>ReLU</h3><p>The most common activation is <strong>ReLU</strong> (Rectified Linear Unit), and its entire rule is:</p><blockquote><strong><em>If the number is negative, output 0. If the number is positive, leave it unchanged.</em></strong></blockquote><p>So ReLU(-3) = 0, ReLU(5) = 5, ReLU(0) = 0, ReLU(8.2) = 8.2.</p><p><strong>Why does something this trivial fix the straight-line problem?</strong> Because ReLU behaves like two different straight lines depending on which side of zero you’re on:</p><ul><li>For negative inputs, it’s the flat line y = 0.</li><li>For positive inputs, it’s the line y = x.</li></ul><p>So ReLU itself is <em>not</em> a single straight line — it’s a line with a <strong>kink</strong> at zero. That sharp corner is the whole point. A straight line has no corners and can never change direction, but the moment you have a <em>bend</em>, you can start building shapes. Combine kinked lines — some bending up, some bending down — and you can build a bump, a curve, anything. A network of ReLU neurons assembles complicated curves out of many tiny straight segments joined at corners, just like a smooth curve on screen is really lots of short straight pixels.</p><p>With the kink in place, stacking neurons no longer collapses to a single line. Depth finally <em>means</em> something.</p><blockquote><strong><em>Try it yourself:</em></strong><em> A neuron has inputs </em><em>[3, 1], weights </em><em>[0.5, -2], bias </em><em>1, and ReLU activation. What&#39;s the output?</em></blockquote><blockquote><strong><em>Answer:</em></strong><em> Weighted sum </em><em>= 3×0.5 + 1×(-2) = 1.5 - 2 = -0.5. Add bias: </em><em>-0.5 + 1 = 0.5. Apply ReLU: </em><em>ReLU(0.5) = 0.5.</em></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=26a4e13c4750" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Neural Networks From Scratch, One Idea at a Time : Part 3]]></title>
            <link>https://medium.com/@rahularyan786/neural-networks-from-scratch-one-idea-at-a-time-part-3-8ba3dc778b8b?source=rss-ebee31f452d4------2</link>
            <guid isPermaLink="false">https://medium.com/p/8ba3dc778b8b</guid>
            <category><![CDATA[bias]]></category>
            <category><![CDATA[weighted-bias]]></category>
            <category><![CDATA[neurons]]></category>
            <dc:creator><![CDATA[rahularyansharma]]></dc:creator>
            <pubDate>Sun, 31 May 2026 02:37:49 GMT</pubDate>
            <atom:updated>2026-05-31T02:37:49.330Z</atom:updated>
            <content:encoded><![CDATA[<h3>The Neuron</h3><p>Here’s the punchline that makes everything click: a single <strong>neuron</strong> does <em>exactly</em> the fruit-bill calculation.</p><p>A neuron has:</p><ul><li>a list of <strong>inputs</strong> — like your quantities [2, 3, 1]</li><li>a list of <strong>weights</strong> — like your prices [10, 5, 20]</li></ul><p>and its core job is to compute the <strong>dot product of inputs and weights</strong> (also called the <strong>weighted sum</strong>). The weights are simply <em>“how much does this input matter”</em> — exactly like a price is <em>“how much does this fruit cost.”</em></p><blockquote><em>A neuron is a dot product wearing a costume.</em></blockquote><h3>The bias</h3><p>But a real shop sometimes adds a flat charge that doesn’t depend on what you bought — a fixed packaging or delivery fee. Say every order has a flat ₹8 added:</p><pre>2*10 + 3*5 + 1*20 + 8 = 63</pre><p>That extra + 8 is the <strong>bias</strong>. A neuron&#39;s complete formula is:</p><blockquote><strong><em>output = (weighted sum of inputs) + bias</em></strong></blockquote><p><strong>Why does a neuron need a bias?</strong> Imagine a neuron with one input, one weight, and no bias: output = weight × input. When the input is 0, the output is <em>forced</em> to be 0, no matter what the weight is. The neuron is chained to the origin.</p><p>But the real world isn’t like that. Picture a neuron deciding “turn on the fan.” You don’t want it reacting at 0 — you want it to stay off until the temperature clears a threshold. That threshold is a fixed offset that has nothing to do with input strength, and the only knob that supplies a fixed offset is the bias.</p><p>The cleanest mental model is the line y = mx + c:</p><ul><li>The <strong>weight</strong> is m, the <em>slope</em> — how steeply the output responds as input grows.</li><li>The <strong>bias</strong> is + c — it <em>shifts the whole line up or down</em>.</li></ul><p>Without c, every line must pass through the origin. With c, you can slide it anywhere.</p><blockquote><strong><em>Weights decide how much each input matters; the bias decides how easy or hard it is for the neuron to “fire” in the first place.</em></strong><em> A big positive bias makes a neuron eager to activate; a big negative bias makes it reluctant.</em></blockquote><p>One more crucial distinction: <strong>weights are input-dependent, the bias is input-independent.</strong> When all inputs are zero, the weighted sum is forced to zero, so the bias is the only thing that can still produce a non-zero output. The weights aren’t meaningless — they simply have no effect on a zero input (anything times zero is zero). Feed in a real input and the weights spring back to life.</p><blockquote><strong><em>Try it yourself:</em></strong><em> A neuron has inputs </em><em>[1, 0], weights </em><em>[0.6, 0.8], and bias </em><em>2. What&#39;s the output?</em></blockquote><blockquote><strong><em>Answer:</em></strong><em> Weighted sum </em><em>= (1×0.6 + 0×0.8) = 0.6. Add bias: </em><em>0.6 + 2 = 2.6.</em></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8ba3dc778b8b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Neural Networks From Scratch, One Idea at a Time : Part 2]]></title>
            <link>https://medium.com/@rahularyan786/neural-networks-from-scratch-one-idea-at-a-time-part-2-4c783d7128de?source=rss-ebee31f452d4------2</link>
            <guid isPermaLink="false">https://medium.com/p/4c783d7128de</guid>
            <category><![CDATA[vector-dot-product]]></category>
            <category><![CDATA[dot-product]]></category>
            <dc:creator><![CDATA[rahularyansharma]]></dc:creator>
            <pubDate>Sat, 30 May 2026 03:48:51 GMT</pubDate>
            <atom:updated>2026-05-30T03:48:51.247Z</atom:updated>
            <content:encoded><![CDATA[<h3>The Dot Product</h3><p>This is the single most important operation in a neural network, and it uses only things you already know: adding and multiplying.</p><p>Forget the name for a minute. Here’s a real situation.</p><p>You go to a shop. You buy <strong>2 apples, 3 bananas, and 1 orange.</strong> The prices are: <strong>apples ₹10 each, bananas ₹5 each, oranges ₹20 each.</strong> What’s the total bill?</p><p>You’d naturally compute:</p><pre>2*10 + 3*5 + 1*20 = 20 + 15 + 20 = 55</pre><p>That’s the dot product. You had two lists:</p><ul><li><strong>Quantities:</strong> [2, 3, 1]</li><li><strong>Prices:</strong> [10, 5, 20]</li></ul><p>And what you did, without being told, was multiply them <strong>position by position</strong> (apples-with-apple-price, bananas-with-banana-price…) and then <strong>add up all the products</strong>.</p><blockquote><strong><em>The dot product of two vectors = multiply them position-by-position, then sum the results.</em></strong><em> It always turns two vectors into a single number.</em></blockquote><p>Notice the <em>pairing</em>: apples only ever multiply with the apple price. First-with-first, second-with-second, third-with-third. Position matters.</p><h3>The “same length” rule</h3><p>The dot product is only defined when <strong>both vectors have the same length</strong> — every position needs a partner. Trying to dot [1, 2, 3] with [4, 5] fails: 1 pairs with 4, 2 pairs with 5, and then 3 has nothing to pair with.</p><blockquote><strong><em>Try it yourself:</em></strong><em> What’s the dot product of </em><em>[1, 2, 3] and </em><em>[4, 5, 6]?</em></blockquote><blockquote><strong><em>Answer:</em></strong><em> </em><em>1*4 + 2*5 + 3*6 = 4 + 10 + 18 = 32</em></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4c783d7128de" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[KV Cache vs Radix Attention vs Page Attention?]]></title>
            <link>https://medium.com/@rahularyan786/kv-cache-vs-radix-attention-vs-page-attention-941ff222be2e?source=rss-ebee31f452d4------2</link>
            <guid isPermaLink="false">https://medium.com/p/941ff222be2e</guid>
            <category><![CDATA[kv-cache]]></category>
            <category><![CDATA[page-attention]]></category>
            <category><![CDATA[radix-attention]]></category>
            <dc:creator><![CDATA[rahularyansharma]]></dc:creator>
            <pubDate>Fri, 29 May 2026 08:07:12 GMT</pubDate>
            <atom:updated>2026-05-29T08:07:12.920Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>KV Cache, Radix Attention, and Paged Attention</strong> are key techniques for efficient LLM inference, particularly for managing memory and computation in long-context, autoregressive generation.</p><h3>1. KV Cache (Foundation)</h3><p>The <strong>KV Cache</strong> is the basic optimization in transformer decoders.</p><p><strong>How it works</strong>: In autoregressive generation (next-token prediction), for each new token, you compute attention over all previous tokens. Instead of recomputing <strong>Keys (K)</strong> and <strong>Values (V)</strong> for past tokens every step, you store them in a cache after the first computation. Queries (Q) for the new token attend to the cached K/V + the new one.</p><p><strong>Benefits</strong>: Dramatically reduces redundant computation (quadratic attention cost avoided for past tokens).</p><p><strong>Drawbacks</strong>:</p><ul><li>Memory scales linearly with sequence length × layers × heads × head dim (can be huge for long contexts/batch sizes).</li><li>Naive implementations cause <strong>memory fragmentation</strong> (hard to allocate contiguous blocks for growing sequences) and poor sharing across requests.</li><li>Cache is usually per-request and discarded after completion.</li></ul><p><strong>KV Cache</strong> is the core mechanism; the others are advanced management strategies built on top of it.</p><h3>2. Paged Attention (vLLM)</h3><p>Introduced by vLLM (2023) to solve <strong>memory fragmentation</strong> in KV cache management.</p><p><strong>How it works</strong>:</p><ul><li>Divide the KV cache into fixed-size <strong>blocks</strong> (pages), like OS virtual memory paging. Each block holds KV for a fixed number of tokens (e.g., 16).</li><li>Use a <strong>block table</strong> (like a page table) to map logical positions in a sequence to physical (possibly non-contiguous) blocks in GPU memory.</li><li>Blocks are allocated on-demand; sequences can grow dynamically without needing large contiguous allocations upfront.</li></ul><p><strong>Key Advantages</strong>:</p><ul><li>Near-zero memory waste and fragmentation.</li><li>Enables higher batch sizes and better throughput.</li><li>Supports <strong>KV block sharing</strong> within/across requests (e.g., for beam search).</li><li>Compatible with continuous batching.</li></ul><p><strong>Use Case</strong>: High-throughput serving where memory efficiency for individual long sequences is critical. It makes LLM serving practical on limited GPU memory.</p><p><strong>Paged Attention</strong> primarily solves <em>where and how</em> to store the KV tensors efficiently in memory.</p><h3>3. Radix Attention (SGLang)</h3><p>Introduced by SGLang (lmsys, 2024) for <strong>automatic prefix sharing and reuse</strong> across multiple requests.</p><p><strong>How it works</strong>:</p><ul><li>Organizes the global KV cache as a <strong>radix tree</strong> (compressed prefix tree), where paths represent token sequences and nodes/edges link to KV cache blocks (often paged).</li><li>When a new request arrives, it searches the tree for the longest matching prefix and reuses the existing KV cache for that prefix.</li><li>New tokens extend the tree. Uses <strong>LRU eviction</strong> (often leaf-first) to manage memory.</li><li>Retains cache across requests instead of discarding it.</li></ul><p><strong>Key Advantages</strong>:</p><ul><li>Excellent for workloads with <strong>common prefixes</strong> (e.g., shared system prompts, multi-turn conversations, agent swarms, RAG with repeated contexts).</li><li>Zero-cost memory sharing for identical prefixes.</li><li>Handles “forking” sequences naturally (branches in the tree).</li><li>Reduces redundant prefill computations significantly.</li></ul><p><strong>Use Case</strong>: Interactive/multi-agent applications, structured generation, or any scenario with high prefix overlap.</p><p><strong>Radix Attention</strong> solves <em>what</em> to cache and <em>how to share</em> it intelligently across requests.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=941ff222be2e" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>