<?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:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:googleplay="http://www.google.com/schemas/play-podcasts/1.0"><channel><title><![CDATA[Deep Life Learning]]></title><description><![CDATA[Articles on DevOps, Machine Learning, Artificial Intelligence and so on. Essays sent when I have something to share (usually a few times a month).]]></description><link>https://blog.x504.dev</link><image><url>https://substackcdn.com/image/fetch/$s_!oGMl!,w_256,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0f8eafa9-e6d4-4c17-8cc8-7158eff85b2e_640x640.png</url><title>Deep Life Learning</title><link>https://blog.x504.dev</link></image><generator>Substack</generator><lastBuildDate>Mon, 05 Oct 2026 19:55:09 GMT</lastBuildDate><atom:link href="https://blog.x504.dev/feed" rel="self" type="application/rss+xml"/><copyright><![CDATA[Alberto Llamas]]></copyright><language><![CDATA[en]]></language><webMaster><![CDATA[albertollamaso@gmail.com]]></webMaster><itunes:owner><itunes:email><![CDATA[albertollamaso@gmail.com]]></itunes:email><itunes:name><![CDATA[x504]]></itunes:name></itunes:owner><itunes:author><![CDATA[x504]]></itunes:author><googleplay:owner><![CDATA[albertollamaso@gmail.com]]></googleplay:owner><googleplay:email><![CDATA[albertollamaso@gmail.com]]></googleplay:email><googleplay:author><![CDATA[x504]]></googleplay:author><itunes:block><![CDATA[Yes]]></itunes:block><item><title><![CDATA[The Engineering Behind LLM Inference]]></title><description><![CDATA[Last week I spent some time diving more into LLM inference. This is a field I personally find interesting, especially because of the optimizations and engineering behind it. It is a tricky optimization problem where the goal is to make LLM inference possible while controlling hardware costs and keeping high quality.]]></description><link>https://blog.x504.dev/p/the-engineering-behind-llm-inference</link><guid isPermaLink="false">https://blog.x504.dev/p/the-engineering-behind-llm-inference</guid><dc:creator><![CDATA[x504]]></dc:creator><pubDate>Mon, 05 Oct 2026 18:01:50 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!ooa2!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa01ed296-43ba-4700-8a5f-06b9945c2b33_1280x719.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!ooa2!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa01ed296-43ba-4700-8a5f-06b9945c2b33_1280x719.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!ooa2!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa01ed296-43ba-4700-8a5f-06b9945c2b33_1280x719.png 424w, https://substackcdn.com/image/fetch/$s_!ooa2!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa01ed296-43ba-4700-8a5f-06b9945c2b33_1280x719.png 848w, https://substackcdn.com/image/fetch/$s_!ooa2!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa01ed296-43ba-4700-8a5f-06b9945c2b33_1280x719.png 1272w, https://substackcdn.com/image/fetch/$s_!ooa2!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa01ed296-43ba-4700-8a5f-06b9945c2b33_1280x719.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!ooa2!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa01ed296-43ba-4700-8a5f-06b9945c2b33_1280x719.png" width="522" height="293.2171875" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/a01ed296-43ba-4700-8a5f-06b9945c2b33_1280x719.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:719,&quot;width&quot;:1280,&quot;resizeWidth&quot;:522,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;Source: https://developer.nvidia.com&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="Source: https://developer.nvidia.com" title="Source: https://developer.nvidia.com" srcset="https://substackcdn.com/image/fetch/$s_!ooa2!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa01ed296-43ba-4700-8a5f-06b9945c2b33_1280x719.png 424w, https://substackcdn.com/image/fetch/$s_!ooa2!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa01ed296-43ba-4700-8a5f-06b9945c2b33_1280x719.png 848w, https://substackcdn.com/image/fetch/$s_!ooa2!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa01ed296-43ba-4700-8a5f-06b9945c2b33_1280x719.png 1272w, https://substackcdn.com/image/fetch/$s_!ooa2!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa01ed296-43ba-4700-8a5f-06b9945c2b33_1280x719.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image buttonBase-GK1x3M"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image buttonBase-GK1x3M"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p style="text-align: justify;">Last week I spent some time diving more into <strong>LLM inference</strong>. This is a field I personally find interesting, especially because of the optimizations and engineering behind it. It is a tricky optimization problem where the goal is to make LLM inference possible while controlling hardware costs and keeping high quality. </p><p style="text-align: justify;">This is post will also find relevant those who want to run open source LLMs on their own infrastructure. There might be multiple reasons to do that, such as cost control to avoid unpredictable per-token pricing, data privacy to keep sensitive data-in-house, lower latency by serving models closer to where the data lives, and greater flexibility to fine-tune or customize models without depending on a third-party provider's roadmap or rate limits among others.</p><p style="text-align: justify;">However, the knowledge required to run those workloads is vast and requires understanding the underlying mode of operation of Large Language Models (LLMs), especially the popular transformer architecture and the SOTA (State of the Art) advances in this area. Let&#8217;s dive in.</p><p></p><h2><strong>The planning Phase</strong></h2><p style="text-align: justify;">First, you have to choose a model for your use case. This is a planning process where you must involve AI engineers, business owners, infra engineers, and DevOps engineers with LLMOps experience. It is very important to know the nuances of choosing different models depending on the business use case.</p><p style="text-align: justify;">For the sake of keeping this article short, let&#8217;s say you have decided to give it a try with <strong><a href="https://huggingface.co/meta-llama/Llama-3.1-8B">Llama3.1 8B</a></strong>. Before taking any further steps, let&#8217;s check what it means by choosing this model.</p><ul><li><p>It is a <strong>multilingual LLM</strong>. It means this model was trained on diverse, multilingual datasets. Hence it has inherit the capacity to do translation. <em>The multilingual part is probably not necessary for your use-case.</em></p></li><li><p>This is a <strong>text in/text out</strong> model. It does not handle images, audios, videos or any other sort of inputs. Only text as input and produce only text as output.</p></li><li><p>It uses a <strong><a href="https://huggingface.co/learn/llm-course/en/chapter1/6">transformer architecture</a></strong>. This is very important to know in advance because there are inference servers that support only transformers.</p></li><li><p>The model uses <strong><a href="https://www.ibm.com/think/topics/grouped-query-attention">Grouped-Query Attention</a></strong> (GQA) for enabling fast inference.</p></li><li><p>Context length: <strong>128k</strong>. This is also very important though 128k of context length is quite long. Ok it depends. For example, if you are planning to use the LLM as a code agent the context length could exponentially grow. Since in the model card say that it support 2 output modalities: Multilingual text and code. We expect the context length to be big enough for using for coding agents.</p></li><li><p>Supported languages: <strong>English, German, French, Italian, Portuguese, Hindi, Spanish, and Thai.</strong></p></li></ul><p></p><p>I was able to gather all of the above information from the model card. Now we need to have an idea of what it will take in terms of resources to run this model in production.</p><p></p><h2><strong>The Resource Estimation Phase</strong></h2><p style="text-align: justify;">One of the first questions you should have: <strong>How much memory will it take to store a model with 8B (billion) parameters in GPU memory (VRAM) using FP16 (half precision)?</strong>.</p><p style="text-align: justify;">The formula to calculate the memory usage for the models weights (parameters) is the following:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!WxYF!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F584a2094-7b57-4f6d-bee7-99f0bf0f0166_789x55.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!WxYF!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F584a2094-7b57-4f6d-bee7-99f0bf0f0166_789x55.png 424w, https://substackcdn.com/image/fetch/$s_!WxYF!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F584a2094-7b57-4f6d-bee7-99f0bf0f0166_789x55.png 848w, https://substackcdn.com/image/fetch/$s_!WxYF!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F584a2094-7b57-4f6d-bee7-99f0bf0f0166_789x55.png 1272w, https://substackcdn.com/image/fetch/$s_!WxYF!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F584a2094-7b57-4f6d-bee7-99f0bf0f0166_789x55.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!WxYF!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F584a2094-7b57-4f6d-bee7-99f0bf0f0166_789x55.png" width="789" height="55" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/584a2094-7b57-4f6d-bee7-99f0bf0f0166_789x55.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:55,&quot;width&quot;:789,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;Article content&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="Article content" title="Article content" srcset="https://substackcdn.com/image/fetch/$s_!WxYF!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F584a2094-7b57-4f6d-bee7-99f0bf0f0166_789x55.png 424w, https://substackcdn.com/image/fetch/$s_!WxYF!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F584a2094-7b57-4f6d-bee7-99f0bf0f0166_789x55.png 848w, https://substackcdn.com/image/fetch/$s_!WxYF!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F584a2094-7b57-4f6d-bee7-99f0bf0f0166_789x55.png 1272w, https://substackcdn.com/image/fetch/$s_!WxYF!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F584a2094-7b57-4f6d-bee7-99f0bf0f0166_789x55.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p style="text-align: justify;">It means that for a model with 8 billion of parameters at half precision (FP16) where each parameter occupies 2 bytes we have:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!QWMu!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5c2602eb-5268-45c0-b6dc-ac28025d0e29_594x63.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!QWMu!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5c2602eb-5268-45c0-b6dc-ac28025d0e29_594x63.png 424w, https://substackcdn.com/image/fetch/$s_!QWMu!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5c2602eb-5268-45c0-b6dc-ac28025d0e29_594x63.png 848w, https://substackcdn.com/image/fetch/$s_!QWMu!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5c2602eb-5268-45c0-b6dc-ac28025d0e29_594x63.png 1272w, https://substackcdn.com/image/fetch/$s_!QWMu!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5c2602eb-5268-45c0-b6dc-ac28025d0e29_594x63.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!QWMu!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5c2602eb-5268-45c0-b6dc-ac28025d0e29_594x63.png" width="594" height="63" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/5c2602eb-5268-45c0-b6dc-ac28025d0e29_594x63.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:63,&quot;width&quot;:594,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;Article content&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="Article content" title="Article content" srcset="https://substackcdn.com/image/fetch/$s_!QWMu!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5c2602eb-5268-45c0-b6dc-ac28025d0e29_594x63.png 424w, https://substackcdn.com/image/fetch/$s_!QWMu!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5c2602eb-5268-45c0-b6dc-ac28025d0e29_594x63.png 848w, https://substackcdn.com/image/fetch/$s_!QWMu!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5c2602eb-5268-45c0-b6dc-ac28025d0e29_594x63.png 1272w, https://substackcdn.com/image/fetch/$s_!QWMu!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5c2602eb-5268-45c0-b6dc-ac28025d0e29_594x63.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p style="text-align: justify;">It means that to only store the model&#8217;s parameters we required at least 16GB of GCPU VRAM.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!mvI_!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F98ed68fb-bb13-4d97-b4a0-4e0b66dd1349_802x687.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!mvI_!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F98ed68fb-bb13-4d97-b4a0-4e0b66dd1349_802x687.png 424w, https://substackcdn.com/image/fetch/$s_!mvI_!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F98ed68fb-bb13-4d97-b4a0-4e0b66dd1349_802x687.png 848w, https://substackcdn.com/image/fetch/$s_!mvI_!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F98ed68fb-bb13-4d97-b4a0-4e0b66dd1349_802x687.png 1272w, https://substackcdn.com/image/fetch/$s_!mvI_!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F98ed68fb-bb13-4d97-b4a0-4e0b66dd1349_802x687.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!mvI_!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F98ed68fb-bb13-4d97-b4a0-4e0b66dd1349_802x687.png" width="802" height="687" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/98ed68fb-bb13-4d97-b4a0-4e0b66dd1349_802x687.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:687,&quot;width&quot;:802,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;Article content&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="Article content" title="Article content" srcset="https://substackcdn.com/image/fetch/$s_!mvI_!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F98ed68fb-bb13-4d97-b4a0-4e0b66dd1349_802x687.png 424w, https://substackcdn.com/image/fetch/$s_!mvI_!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F98ed68fb-bb13-4d97-b4a0-4e0b66dd1349_802x687.png 848w, https://substackcdn.com/image/fetch/$s_!mvI_!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F98ed68fb-bb13-4d97-b4a0-4e0b66dd1349_802x687.png 1272w, https://substackcdn.com/image/fetch/$s_!mvI_!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F98ed68fb-bb13-4d97-b4a0-4e0b66dd1349_802x687.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image buttonBase-GK1x3M"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image buttonBase-GK1x3M"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">Memory layout when serving an LLM with 8B parameters on NVIDIA A100 (40 GB)</figcaption></figure></div><p style="text-align: justify;">In order to have an idea how the VRAM is a bottleneck, we can see in the image below the GPU memory usage distribution when upgrading to a model with 13B of parameters.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!F3vi!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fceaf963e-5108-4ff8-925f-0453462fa384_802x687.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!F3vi!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fceaf963e-5108-4ff8-925f-0453462fa384_802x687.png 424w, https://substackcdn.com/image/fetch/$s_!F3vi!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fceaf963e-5108-4ff8-925f-0453462fa384_802x687.png 848w, https://substackcdn.com/image/fetch/$s_!F3vi!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fceaf963e-5108-4ff8-925f-0453462fa384_802x687.png 1272w, https://substackcdn.com/image/fetch/$s_!F3vi!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fceaf963e-5108-4ff8-925f-0453462fa384_802x687.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!F3vi!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fceaf963e-5108-4ff8-925f-0453462fa384_802x687.png" width="802" height="687" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/ceaf963e-5108-4ff8-925f-0453462fa384_802x687.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:687,&quot;width&quot;:802,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;Article content&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="Article content" title="Article content" srcset="https://substackcdn.com/image/fetch/$s_!F3vi!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fceaf963e-5108-4ff8-925f-0453462fa384_802x687.png 424w, https://substackcdn.com/image/fetch/$s_!F3vi!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fceaf963e-5108-4ff8-925f-0453462fa384_802x687.png 848w, https://substackcdn.com/image/fetch/$s_!F3vi!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fceaf963e-5108-4ff8-925f-0453462fa384_802x687.png 1272w, https://substackcdn.com/image/fetch/$s_!F3vi!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fceaf963e-5108-4ff8-925f-0453462fa384_802x687.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image buttonBase-GK1x3M"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image buttonBase-GK1x3M"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">Memory layout when serving an LLM with 13B parameters on NVIDIA A100 (40 GB)</figcaption></figure></div><p style="text-align: justify;">We can immediately notice that using same hardware and upgrading our model we are reserving less memory space for KV cache which has an impact in model latency (negative), throughput (negative) and accuracy (probably positive due the increase of numbers of parameters). We will always need to make tradeoffs as shown in the figure below.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!3-SO!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fadb24b9c-dfb4-4328-8093-3d91d2cb6626_352x347.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!3-SO!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fadb24b9c-dfb4-4328-8093-3d91d2cb6626_352x347.png 424w, https://substackcdn.com/image/fetch/$s_!3-SO!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fadb24b9c-dfb4-4328-8093-3d91d2cb6626_352x347.png 848w, https://substackcdn.com/image/fetch/$s_!3-SO!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fadb24b9c-dfb4-4328-8093-3d91d2cb6626_352x347.png 1272w, https://substackcdn.com/image/fetch/$s_!3-SO!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fadb24b9c-dfb4-4328-8093-3d91d2cb6626_352x347.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!3-SO!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fadb24b9c-dfb4-4328-8093-3d91d2cb6626_352x347.png" width="352" height="347" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/adb24b9c-dfb4-4328-8093-3d91d2cb6626_352x347.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:347,&quot;width&quot;:352,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;Article content&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="Article content" title="Article content" srcset="https://substackcdn.com/image/fetch/$s_!3-SO!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fadb24b9c-dfb4-4328-8093-3d91d2cb6626_352x347.png 424w, https://substackcdn.com/image/fetch/$s_!3-SO!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fadb24b9c-dfb4-4328-8093-3d91d2cb6626_352x347.png 848w, https://substackcdn.com/image/fetch/$s_!3-SO!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fadb24b9c-dfb4-4328-8093-3d91d2cb6626_352x347.png 1272w, https://substackcdn.com/image/fetch/$s_!3-SO!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fadb24b9c-dfb4-4328-8093-3d91d2cb6626_352x347.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image buttonBase-GK1x3M"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image buttonBase-GK1x3M"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p style="text-align: justify;">For each generated token, caches must stores a key and value vector per transformer layer and head. It is very important that you calculate and have an estimation of the potential KV usage.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Llab!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1eb5885e-6639-456f-8090-a2fc378ca01b_739x266.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Llab!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1eb5885e-6639-456f-8090-a2fc378ca01b_739x266.png 424w, https://substackcdn.com/image/fetch/$s_!Llab!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1eb5885e-6639-456f-8090-a2fc378ca01b_739x266.png 848w, https://substackcdn.com/image/fetch/$s_!Llab!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1eb5885e-6639-456f-8090-a2fc378ca01b_739x266.png 1272w, https://substackcdn.com/image/fetch/$s_!Llab!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1eb5885e-6639-456f-8090-a2fc378ca01b_739x266.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Llab!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1eb5885e-6639-456f-8090-a2fc378ca01b_739x266.png" width="739" height="266" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/1eb5885e-6639-456f-8090-a2fc378ca01b_739x266.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:266,&quot;width&quot;:739,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;Article content&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="Article content" title="Article content" srcset="https://substackcdn.com/image/fetch/$s_!Llab!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1eb5885e-6639-456f-8090-a2fc378ca01b_739x266.png 424w, https://substackcdn.com/image/fetch/$s_!Llab!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1eb5885e-6639-456f-8090-a2fc378ca01b_739x266.png 848w, https://substackcdn.com/image/fetch/$s_!Llab!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1eb5885e-6639-456f-8090-a2fc378ca01b_739x266.png 1272w, https://substackcdn.com/image/fetch/$s_!Llab!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1eb5885e-6639-456f-8090-a2fc378ca01b_739x266.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image buttonBase-GK1x3M"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image buttonBase-GK1x3M"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p style="text-align: justify;">One way to get this information without loading the model is checking the <strong><a href="https://huggingface.co/meta-llama/Llama-3.1-8B/blob/main/config.json">config.json</a></strong> in Hugging Face.</p><p style="text-align: justify;">We will see that the variables names are slightly different but here are the naming conventions:</p><pre><code><code>n_layers -&gt; num_hidden_layers
n_heads -&gt; num_attention_heads
d_model -&gt; hidden_size
d_head = hidden_size / num_attention_heads</code></code></pre><p></p><p style="text-align: justify;">Doing the math, we can come with the result that for the <strong><a href="https://huggingface.co/meta-llama/Llama-3.1-8B">Llama3.1 8B</a> </strong>model in FP16 (2 bytes per element), we will need approximately 0,52MB per-token KV cache. For the full 131&#8217;072 (128k) context window, the KV cache size is about <strong>68,7 GiB</strong>.</p><p style="text-align: justify;">That is for Batch size equal to 1. When we increase the batch size, the total memory footprint scales linearly with each additional sequence.</p><p style="text-align: justify;">Now we understand that the KV cache prevents us from generating very long sequences and from processing large batches. This is one of the main reasons we need to apply optimizations techniques like quantization (more on this later), KV cache offload, continuous batching and others we will see later.</p><p style="text-align: justify;">As you might noticed, if we want to run full context of 128K for the 8B parameter Llama model we are using on this article and using the same hardware (NVIDIA A100 - 40 GB). We cannot run even 1 inference query. We will run in OOM. The only option is upgrade hardware, apply quantization or use a smaller model.</p><p></p><h2><strong>Optimizations</strong></h2><p style="text-align: justify;">In this section, I present a brief overview of the optimizations most commonly used in LLM inference. Most are already implemented in inference frameworks such as <strong><a href="https://www.sglang.io/">SGLang</a></strong>, <strong><a href="https://vllm.ai/">vLLM</a></strong> and <strong><a href="https://llm-d.ai/">llm-d.</a></strong></p><p></p><h3><strong>1-Paged Attention</strong></h3><p style="text-align: justify;">First published in the now widely cited paper <strong><a href="https://arc.net/l/quote/lhfycrrb">Efficient Memory Management for Large Language Model Serving with PagedAttention.</a></strong></p><p style="text-align: justify;">This is a technique to manage efficiently the KV cache memory of the GPU. It is inspired by the algorithm utilized in classical virtual memory and paging techniques in operating systems.</p><p style="text-align: justify;">In earlier systems, KV cache allocation per request or batch reserved memory that went unused. Each allocation reserved space matching the context length limit for the duration of generation, which constrained batch size. <strong>PagedAttention</strong> improves the memory management, cutting waste to under <strong>4%</strong> and increasing throughput by <strong>2-3x</strong>.</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!_D81!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faa7024fd-9848-4332-9e5d-dd6c75c9accb_973x228.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!_D81!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faa7024fd-9848-4332-9e5d-dd6c75c9accb_973x228.png 424w, https://substackcdn.com/image/fetch/$s_!_D81!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faa7024fd-9848-4332-9e5d-dd6c75c9accb_973x228.png 848w, https://substackcdn.com/image/fetch/$s_!_D81!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faa7024fd-9848-4332-9e5d-dd6c75c9accb_973x228.png 1272w, https://substackcdn.com/image/fetch/$s_!_D81!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faa7024fd-9848-4332-9e5d-dd6c75c9accb_973x228.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!_D81!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faa7024fd-9848-4332-9e5d-dd6c75c9accb_973x228.png" width="973" height="228" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/aa7024fd-9848-4332-9e5d-dd6c75c9accb_973x228.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:228,&quot;width&quot;:973,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;Article content&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="Article content" title="Article content" srcset="https://substackcdn.com/image/fetch/$s_!_D81!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faa7024fd-9848-4332-9e5d-dd6c75c9accb_973x228.png 424w, https://substackcdn.com/image/fetch/$s_!_D81!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faa7024fd-9848-4332-9e5d-dd6c75c9accb_973x228.png 848w, https://substackcdn.com/image/fetch/$s_!_D81!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faa7024fd-9848-4332-9e5d-dd6c75c9accb_973x228.png 1272w, https://substackcdn.com/image/fetch/$s_!_D81!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faa7024fd-9848-4332-9e5d-dd6c75c9accb_973x228.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><h3><strong>2-Prefix Caching</strong></h3><p style="text-align: justify;">This is a technique utilized to avoid redundant prompt computations. The approach is to cache the kv-blocks of processed requests, and reuse these blocks when a new request comes in with the same prefix as previous requests.</p><p style="text-align: justify;">As shown in the image below we can see two scenarios when prefix caching is utilized. The first one is when different users utilized the same system prompt (for instance in RAG), this prompt is computed only the first time and then subsequently loaded from cache.</p><p style="text-align: justify;">The second example is when a single user is having a multi-turn conversation with the LLM. The session length or context from previous rounds are cached and then subsequently loaded from cache to avoid to re-compute it again.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!n7wt!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F99b44563-43ae-4b8e-b9b7-fefd6c2d64e9_1130x433.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!n7wt!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F99b44563-43ae-4b8e-b9b7-fefd6c2d64e9_1130x433.png 424w, https://substackcdn.com/image/fetch/$s_!n7wt!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F99b44563-43ae-4b8e-b9b7-fefd6c2d64e9_1130x433.png 848w, https://substackcdn.com/image/fetch/$s_!n7wt!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F99b44563-43ae-4b8e-b9b7-fefd6c2d64e9_1130x433.png 1272w, https://substackcdn.com/image/fetch/$s_!n7wt!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F99b44563-43ae-4b8e-b9b7-fefd6c2d64e9_1130x433.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!n7wt!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F99b44563-43ae-4b8e-b9b7-fefd6c2d64e9_1130x433.png" width="1130" height="433" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/99b44563-43ae-4b8e-b9b7-fefd6c2d64e9_1130x433.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:433,&quot;width&quot;:1130,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;Article content&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="Article content" title="Article content" srcset="https://substackcdn.com/image/fetch/$s_!n7wt!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F99b44563-43ae-4b8e-b9b7-fefd6c2d64e9_1130x433.png 424w, https://substackcdn.com/image/fetch/$s_!n7wt!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F99b44563-43ae-4b8e-b9b7-fefd6c2d64e9_1130x433.png 848w, https://substackcdn.com/image/fetch/$s_!n7wt!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F99b44563-43ae-4b8e-b9b7-fefd6c2d64e9_1130x433.png 1272w, https://substackcdn.com/image/fetch/$s_!n7wt!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F99b44563-43ae-4b8e-b9b7-fefd6c2d64e9_1130x433.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image buttonBase-GK1x3M"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image buttonBase-GK1x3M"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption"></figcaption></figure></div><p style="text-align: justify;">We can see in figure below how by using prefix-caching we can increase the throughput during inference.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!imPK!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F503b0b2c-d734-4fda-b5e8-7707b9800408_1075x539.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!imPK!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F503b0b2c-d734-4fda-b5e8-7707b9800408_1075x539.png 424w, https://substackcdn.com/image/fetch/$s_!imPK!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F503b0b2c-d734-4fda-b5e8-7707b9800408_1075x539.png 848w, https://substackcdn.com/image/fetch/$s_!imPK!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F503b0b2c-d734-4fda-b5e8-7707b9800408_1075x539.png 1272w, https://substackcdn.com/image/fetch/$s_!imPK!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F503b0b2c-d734-4fda-b5e8-7707b9800408_1075x539.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!imPK!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F503b0b2c-d734-4fda-b5e8-7707b9800408_1075x539.png" width="1075" height="539" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/503b0b2c-d734-4fda-b5e8-7707b9800408_1075x539.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:539,&quot;width&quot;:1075,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;Article content&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="Article content" title="Article content" srcset="https://substackcdn.com/image/fetch/$s_!imPK!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F503b0b2c-d734-4fda-b5e8-7707b9800408_1075x539.png 424w, https://substackcdn.com/image/fetch/$s_!imPK!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F503b0b2c-d734-4fda-b5e8-7707b9800408_1075x539.png 848w, https://substackcdn.com/image/fetch/$s_!imPK!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F503b0b2c-d734-4fda-b5e8-7707b9800408_1075x539.png 1272w, https://substackcdn.com/image/fetch/$s_!imPK!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F503b0b2c-d734-4fda-b5e8-7707b9800408_1075x539.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image buttonBase-GK1x3M"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image buttonBase-GK1x3M"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p></p><h3><strong>3-Parallelism</strong></h3><p style="text-align: justify;">There are multiple forms of parallelism within inference systems. This technique allow FLOP operations at different layers to be executed in parallel.</p><p style="text-align: justify;">I am not going to go deeper into each on these forms but I will briefly mention them on this article.</p><p style="text-align: justify;"><strong>Data parallelism:</strong> Groups multiple independent requests into batches.</p><p style="text-align: justify;"><strong>Tensor Parallelism:</strong> This is a technique that split layer-wise the weights of transformer model and computations are assigned to independent GPU cores.</p><p style="text-align: justify;"><strong>Pipeline</strong> <strong>Parallelism: </strong>Mostly used when using big LLMs with multiple GPUs nodes. Basically is a technique to partition the model layer-wise, assigning different layers to separate GPUs for computing.</p><p style="text-align: justify;"><strong>3D</strong> <strong>Parallelism: Combined them all</strong></p><p style="text-align: justify;">There is also <strong>Expert Parallelism</strong> for Mixture-of-Experts (MoE) architecture but I am not going to talk about this one on this article.</p><p style="text-align: justify;">From <strong><a href="https://docs.vllm.ai/en/stable/serving/parallelism_scaling/">vLLM documentation</a></strong> they recommend when using vLLM the following approaches:</p><ul><li><p><strong>Single GPU (no distributed inference):</strong> if the model fits on a single GPU, distributed inference is probably unnecessary. Run inference on that GPU.</p></li><li><p><strong>Single-node multi-GPU using tensor parallel inference:</strong> if the model is too large for a single GPU but fits on a single node with multiple GPUs, use <em>tensor parallelism</em>. For example, set tensor_parallel_size=4 when using a node with 4 GPUs.</p></li><li><p><strong>Multi-node multi-GPU using tensor parallel and pipeline parallel inference:</strong> if the model is too large for a single node, combine <em>tensor parallelism</em> with <em>pipeline parallelism</em>. Set tensor_parallel_size to the number of GPUs per node and pipeline_parallel_size to the number of nodes. For example, set tensor_parallel_size=8 and pipeline_parallel_size=2 when using 2 nodes with 8 GPUs per node.</p></li></ul><p></p><h3><strong>4-Quantization</strong></h3><p style="text-align: justify;">LLM model&#8217;s parameters are continuously growing. As shown before, it is required to stores all parameters in memory (GPU VRAM). This means the total model size sets the minimum memory requirement.</p><p style="text-align: justify;">Quantization is a method to make models smaller to overcome this issue. Parameters are usually stored in floating-point numbers and inference involves a huge amounts of floating-point operations (FLOPS). There are different floating-point precisions such as FP32, FP16, BF16, INT8, INT4. By lowering the precision we massively reduce the memory usage but at the potential cost of reducing accuracy.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!8CWe!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe2e2e111-4bc9-4fbb-be02-9648dc1f4f26_1144x856.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!8CWe!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe2e2e111-4bc9-4fbb-be02-9648dc1f4f26_1144x856.png 424w, https://substackcdn.com/image/fetch/$s_!8CWe!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe2e2e111-4bc9-4fbb-be02-9648dc1f4f26_1144x856.png 848w, https://substackcdn.com/image/fetch/$s_!8CWe!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe2e2e111-4bc9-4fbb-be02-9648dc1f4f26_1144x856.png 1272w, https://substackcdn.com/image/fetch/$s_!8CWe!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe2e2e111-4bc9-4fbb-be02-9648dc1f4f26_1144x856.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!8CWe!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe2e2e111-4bc9-4fbb-be02-9648dc1f4f26_1144x856.png" width="1144" height="856" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/e2e2e111-4bc9-4fbb-be02-9648dc1f4f26_1144x856.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:856,&quot;width&quot;:1144,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;Article content&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="Article content" title="Article content" srcset="https://substackcdn.com/image/fetch/$s_!8CWe!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe2e2e111-4bc9-4fbb-be02-9648dc1f4f26_1144x856.png 424w, https://substackcdn.com/image/fetch/$s_!8CWe!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe2e2e111-4bc9-4fbb-be02-9648dc1f4f26_1144x856.png 848w, https://substackcdn.com/image/fetch/$s_!8CWe!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe2e2e111-4bc9-4fbb-be02-9648dc1f4f26_1144x856.png 1272w, https://substackcdn.com/image/fetch/$s_!8CWe!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe2e2e111-4bc9-4fbb-be02-9648dc1f4f26_1144x856.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image buttonBase-GK1x3M"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image buttonBase-GK1x3M"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p style="text-align: justify;">LLM compression improves both throughput and latency and <strong>done correctly</strong>, it does not significantly degrade the performance of the model.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!YSLx!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff8e89bc7-54e1-4e33-b943-54be1f532a04_1047x523.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!YSLx!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff8e89bc7-54e1-4e33-b943-54be1f532a04_1047x523.png 424w, https://substackcdn.com/image/fetch/$s_!YSLx!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff8e89bc7-54e1-4e33-b943-54be1f532a04_1047x523.png 848w, https://substackcdn.com/image/fetch/$s_!YSLx!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff8e89bc7-54e1-4e33-b943-54be1f532a04_1047x523.png 1272w, https://substackcdn.com/image/fetch/$s_!YSLx!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff8e89bc7-54e1-4e33-b943-54be1f532a04_1047x523.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!YSLx!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff8e89bc7-54e1-4e33-b943-54be1f532a04_1047x523.png" width="1047" height="523" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/f8e89bc7-54e1-4e33-b943-54be1f532a04_1047x523.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:523,&quot;width&quot;:1047,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;Article content&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="Article content" title="Article content" srcset="https://substackcdn.com/image/fetch/$s_!YSLx!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff8e89bc7-54e1-4e33-b943-54be1f532a04_1047x523.png 424w, https://substackcdn.com/image/fetch/$s_!YSLx!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff8e89bc7-54e1-4e33-b943-54be1f532a04_1047x523.png 848w, https://substackcdn.com/image/fetch/$s_!YSLx!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff8e89bc7-54e1-4e33-b943-54be1f532a04_1047x523.png 1272w, https://substackcdn.com/image/fetch/$s_!YSLx!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff8e89bc7-54e1-4e33-b943-54be1f532a04_1047x523.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image buttonBase-GK1x3M"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image buttonBase-GK1x3M"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><h3><strong>5-Speculative Decoding</strong></h3><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!ef6A!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0bd9cdf7-a7e4-435a-9b6d-3161cfb9e2c2_937x476.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!ef6A!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0bd9cdf7-a7e4-435a-9b6d-3161cfb9e2c2_937x476.png 424w, https://substackcdn.com/image/fetch/$s_!ef6A!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0bd9cdf7-a7e4-435a-9b6d-3161cfb9e2c2_937x476.png 848w, https://substackcdn.com/image/fetch/$s_!ef6A!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0bd9cdf7-a7e4-435a-9b6d-3161cfb9e2c2_937x476.png 1272w, https://substackcdn.com/image/fetch/$s_!ef6A!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0bd9cdf7-a7e4-435a-9b6d-3161cfb9e2c2_937x476.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!ef6A!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0bd9cdf7-a7e4-435a-9b6d-3161cfb9e2c2_937x476.png" width="937" height="476" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/0bd9cdf7-a7e4-435a-9b6d-3161cfb9e2c2_937x476.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:476,&quot;width&quot;:937,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;Article content&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="Article content" title="Article content" srcset="https://substackcdn.com/image/fetch/$s_!ef6A!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0bd9cdf7-a7e4-435a-9b6d-3161cfb9e2c2_937x476.png 424w, https://substackcdn.com/image/fetch/$s_!ef6A!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0bd9cdf7-a7e4-435a-9b6d-3161cfb9e2c2_937x476.png 848w, https://substackcdn.com/image/fetch/$s_!ef6A!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0bd9cdf7-a7e4-435a-9b6d-3161cfb9e2c2_937x476.png 1272w, https://substackcdn.com/image/fetch/$s_!ef6A!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0bd9cdf7-a7e4-435a-9b6d-3161cfb9e2c2_937x476.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image buttonBase-GK1x3M"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image buttonBase-GK1x3M"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption"></figcaption></figure></div><p style="text-align: justify;">This is a technique to speed up inference. Due the fact that autoregressive generation will generate a single token for every full forward pass. This a sequential process resulting the GPU compute power to stay idle most of the time.</p><p style="text-align: justify;"><em>Speculative decoding</em> is technique that combine a target model and a draft model (a more smaller one) in a mechanism where the draft model proposes multiple token for the next generation and the target model verifies those proposals (all of them) in a single forward pass.</p><p style="text-align: justify;">Compared with standard autoregressive decoding, which produces on token per pass, this technique reduce the latency during inference and boosting the throughput without any impact on accuracy.</p><p></p><h3><strong>6-Cache Aware Routing</strong></h3><p style="text-align: justify;">Often the LLM you need to deploy does not fit in a single GPU or even if it does you need multiple GPUs to increase the throughput of the system to be able to serve more users.</p><p style="text-align: justify;">In a distributed system when an user send multiple requests during the same session usually you cache them in one server to reduce computing across the whole system.</p><p style="text-align: justify;">In distribute inference for LLMs we do something similar. When user is interacting with the LLM asking questions, refining answers, perhaps the LLM is calling tools or sub-agents everything during the same session or context, you don&#8217;t want to recompute and cache the context every time and in all machines. This will be a waste of resources.</p><p style="text-align: justify;">A technique to solve this is called <strong>KV cache aware routing</strong>. This mechanism makes intelligent routing decisions based on KV cache awareness.</p><p style="text-align: justify;">The way it works is for example the user send a request to the router like this:</p><pre><code><code>curl http://localhost:30080/v1/completions \
  -H "Content-Type: application/json" \
  -d '{
    "model": "meta-llama/Llama-3.2-1B-Instruct",
    "prompt": "What is the capital of France?",
    "max_tokens": 100
  }'</code></code></pre><p>Then, send another request with the same prompt prefix:</p><pre><code><code>curl http://localhost:30080/v1/completions \
  -H "Content-Type: application/json" \
  -d '{
    "model": "meta-llama/Llama-3.2-1B-Instruct",
    "prompt": "What is the capital of France? And what is its population?",
    "max_tokens": 100
  }'</code></code></pre><p style="text-align: justify;">You should observe that the second request is routed to the same instance as the first request. This is because the KV cache aware router detects that the second request shares a prefix with the first request and routes it to the same instance to maximize KV cache utilization.</p><h2><strong>Conclusions</strong></h2><p style="text-align: justify;">As you have seen it is not trivial to run LLMs in your own hardware. There are a lot of tweaks to make and decisions to take depending on your use-case. Also take this article as a basic reference as I am omitting more advanced techniques and I am not going tin depth on the ones mentioned in the article. Thanks for reading!</p><p></p><p><strong>Sources</strong></p><ul><li><p><strong><a href="https://horace.io/brrr_intro.html">https://horace.io/brrr_intro.html</a></strong></p></li></ul><div id="youtube2-6OBtO9niT00" class="youtube-wrap" data-attrs="{&quot;videoId&quot;:&quot;6OBtO9niT00&quot;,&quot;startTime&quot;:null,&quot;endTime&quot;:null}" data-component-name="Youtube2ToDOM"><div class="youtube-inner"><iframe src="https://www.youtube-nocookie.com/embed/6OBtO9niT00?rel=0&amp;autoplay=0&amp;showinfo=0&amp;enablejsapi=0" frameborder="0" loading="lazy" gesture="media" allow="autoplay; fullscreen" allowautoplay="true" allowfullscreen="true" width="728" height="409"></iframe></div></div><div class="embedded-post-wrap" data-attrs="{&quot;id&quot;:191705644,&quot;url&quot;:&quot;https://kipp.ly/p/transformer-inference-arithmetic&quot;,&quot;publication_id&quot;:101674,&quot;embedding_publication_id&quot;:2228169,&quot;publication_name&quot;:&quot;kipply's blog&quot;,&quot;publication_logo_url&quot;:&quot;https://substackcdn.com/image/fetch/$s_!qmMV!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F004ddee4-0698-47dc-9f49-7fd4146e771b_399x399.png&quot;,&quot;title&quot;:&quot;Transformer Inference Arithmetic&quot;,&quot;truncated_body_text&quot;:&quot;This article presents detailed few-principles reasoning about large language model inference performance, with no experiments or difficult math. The amount of understanding that can be acquired this way is really impressive and practical! A very simple model of latency for inference turns out to be a good fit for emprical results. It's helped me make be&#8230;&quot;,&quot;date&quot;:&quot;2022-03-30T00:00:00.000Z&quot;,&quot;like_count&quot;:25,&quot;comment_count&quot;:1,&quot;bylines&quot;:[],&quot;utm_campaign&quot;:null,&quot;belowTheFold&quot;:true,&quot;type&quot;:&quot;newsletter&quot;,&quot;language&quot;:&quot;en&quot;,&quot;source&quot;:null}" data-component-name="EmbeddedPostToDOM"><a class="embedded-post" native="true" href="https://kipp.ly/p/transformer-inference-arithmetic?utm_source=substack&amp;utm_campaign=post_embed&amp;utm_medium=web&amp;embedding_publication_id=2228169"><div class="embedded-post-header"><img class="embedded-post-publication-logo" src="https://substackcdn.com/image/fetch/$s_!qmMV!,w_56,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F004ddee4-0698-47dc-9f49-7fd4146e771b_399x399.png" loading="lazy"><span class="embedded-post-publication-name">kipply's blog</span></div><div class="embedded-post-title-wrapper"><div class="embedded-post-title">Transformer Inference Arithmetic</div></div><div class="embedded-post-body">This article presents detailed few-principles reasoning about large language model inference performance, with no experiments or difficult math. The amount of understanding that can be acquired this way is really impressive and practical! A very simple model of latency for inference turns out to be a good fit for emprical results. It's helped me make be&#8230;</div><div class="embedded-post-cta-wrapper"><span class="embedded-post-cta">Read more</span></div><div class="embedded-post-meta">5 years ago &#183; 25 likes &#183; 1 comment</div></a></div><div id="youtube2-fcgPYo3OtV0" class="youtube-wrap" data-attrs="{&quot;videoId&quot;:&quot;fcgPYo3OtV0&quot;,&quot;startTime&quot;:null,&quot;endTime&quot;:null}" data-component-name="Youtube2ToDOM"><div class="youtube-inner"><iframe src="https://www.youtube-nocookie.com/embed/fcgPYo3OtV0?rel=0&amp;autoplay=0&amp;showinfo=0&amp;enablejsapi=0" frameborder="0" loading="lazy" gesture="media" allow="autoplay; fullscreen" allowautoplay="true" allowfullscreen="true" width="728" height="409"></iframe></div></div><ul><li><p><strong><a href="https://www.databricks.com/blog/llm-inference-performance-engineering-best-practices">https://www.databricks.com/blog/llm-inference-performance-engineering-best-practices</a></strong></p></li><li><p><strong><a href="https://hamzaelshafie.bearblog.dev/paged-attention-from-first-principles-a-view-inside-vllm/">https://hamzaelshafie.bearblog.dev/paged-attention-from-first-principles-a-view-inside-vllm/</a></strong></p></li><li><p><strong><a href="https://vllm.ai/blog/2023-06-20-vllm">https://vllm.ai/blog/2023-06-20-vllm</a></strong></p></li><li><p><strong><a href="https://arxiv.org/abs/2309.06180">https://arxiv.org/abs/2309.06180</a></strong></p></li><li><p><strong><a href="https://vllm.ai/blog/2025-09-05-anatomy-of-vllm">https://vllm.ai/blog/2025-09-05-anatomy-of-vllm</a></strong></p></li><li><p><strong><a href="https://vllm.ai/blog/2025-01-27-v1-alpha-release">https://vllm.ai/blog/2025-01-27-v1-alpha-release</a></strong></p></li><li><p><strong><a href="https://developer.nvidia.com/blog/an-introduction-to-speculative-decoding-for-reducing-latency-in-ai-inference/">https://developer.nvidia.com/blog/an-introduction-to-speculative-decoding-for-reducing-latency-in-ai-inference/</a></strong></p></li><li><p><strong><a href="https://www.aleksagordic.com/blog/vllm#cpt1">https://www.aleksagordic.com/blog/vllm#cpt1</a></strong></p></li><li><p><strong><a href="https://docs.vllm.ai/en/stable/serving/parallelism_scaling/">https://docs.vllm.ai/en/stable/serving/parallelism_scaling/</a></strong></p></li><li><p><strong><a href="https://medium.com/@chenhao511132/parallelism-in-llm-inference-c0b6bdc5f693">https://medium.com/@chenhao511132/parallelism-in-llm-inference-c0b6bdc5f693</a></strong></p></li></ul>]]></content:encoded></item><item><title><![CDATA[Update Your Damn Dependencies]]></title><description><![CDATA[Hello there and Happy Halloween &#127875;&#127875;&#127875;.]]></description><link>https://blog.x504.dev/p/update-your-damn-dependencies</link><guid isPermaLink="false">https://blog.x504.dev/p/update-your-damn-dependencies</guid><dc:creator><![CDATA[x504]]></dc:creator><pubDate>Sat, 01 Nov 2025 07:56:53 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!3OsV!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1cc62896-1a4e-4e67-ba5c-40e2b7ca7af0_1014x640.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Hello there and Happy Halloween &#127875;&#127875;&#127875;.</p><p>Wether you are a DevOps Engineer, Platform Engineer, or SRE, you might know <a href="https://docs.renovatebot.com/">Renovate</a> &#8212; an automated dependency update tool.</p><p>It helps keep your infrastructure up to date without almost manual intervention. In this post, I&#8217;ll show how Renovate can be extended to make the most of it. While the examples focus on cloud infrastructure and DevOps, the same approach can be applied by developers who want to keep their code packages and libraries up to date.</p><h2>How Renovate works?</h2><p>There are many ways to use it. You can run it as a Github Action, you can self-host your own Renovate server or you can do what majority do which is install the <a href="https://github.com/apps/renovate">Renovate App</a> in your version control system, let&#8217;s say GitHub and then allow Renovate access to the repositories you want to enable it.</p><p>Once is installed, you can create a JSON file in your repository with any of the following filenames where you will store the Renovate configuration:</p><ol><li><p><code>renovate.json</code></p></li><li><p><code>renovate.json5</code></p></li><li><p><code>.github/renovate.json</code></p></li><li><p><code>.github/renovate.json5</code></p></li><li><p><code>.gitlab/renovate.json</code></p></li><li><p><code>.gitlab/renovate.json5</code></p></li><li><p><code>.renovaterc</code></p></li><li><p><code>.renovaterc.json</code></p></li><li><p><code>.renovaterc.json5</code></p></li><li><p><code>package.json</code> <em>(within a </em><code>&#8220;renovate&#8221;</code><em> section)</em></p></li></ol><p></p><p>Renovate bot will pickup the configuration and act accordingly.</p><p>When it comes to the configuration and starting with Renovate, it is recommended to use one of the <a href="https://docs.renovatebot.com/presets-config/">presets</a>. These presets contains best practices recommended by Renovate maintainers. One of the most popular presets is &#8220;config:recommended&#8221; which basically encapsulate the following configuration:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!3OsV!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1cc62896-1a4e-4e67-ba5c-40e2b7ca7af0_1014x640.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!3OsV!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1cc62896-1a4e-4e67-ba5c-40e2b7ca7af0_1014x640.png 424w, https://substackcdn.com/image/fetch/$s_!3OsV!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1cc62896-1a4e-4e67-ba5c-40e2b7ca7af0_1014x640.png 848w, https://substackcdn.com/image/fetch/$s_!3OsV!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1cc62896-1a4e-4e67-ba5c-40e2b7ca7af0_1014x640.png 1272w, https://substackcdn.com/image/fetch/$s_!3OsV!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1cc62896-1a4e-4e67-ba5c-40e2b7ca7af0_1014x640.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!3OsV!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1cc62896-1a4e-4e67-ba5c-40e2b7ca7af0_1014x640.png" width="506" height="319.3688362919132" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/1cc62896-1a4e-4e67-ba5c-40e2b7ca7af0_1014x640.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:640,&quot;width&quot;:1014,&quot;resizeWidth&quot;:506,&quot;bytes&quot;:95924,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.deeplifelearning.com/i/177091282?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1cc62896-1a4e-4e67-ba5c-40e2b7ca7af0_1014x640.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!3OsV!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1cc62896-1a4e-4e67-ba5c-40e2b7ca7af0_1014x640.png 424w, https://substackcdn.com/image/fetch/$s_!3OsV!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1cc62896-1a4e-4e67-ba5c-40e2b7ca7af0_1014x640.png 848w, https://substackcdn.com/image/fetch/$s_!3OsV!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1cc62896-1a4e-4e67-ba5c-40e2b7ca7af0_1014x640.png 1272w, https://substackcdn.com/image/fetch/$s_!3OsV!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1cc62896-1a4e-4e67-ba5c-40e2b7ca7af0_1014x640.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image buttonBase-GK1x3M"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image buttonBase-GK1x3M"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p></p><p>Find more about presets <a href="https://docs.renovatebot.com/presets-config/">here</a>. I encourage you to get familiar with them.</p><p>Another important part of the configuration is the schedule cadence. Scheduling allows you to define when you want to Renovate to scan your repository and create Pull Requests. There are infinite use cases and it depends on each team but the most commons are:</p><ul><li><p>Run Renovate outside office hours, to free up continuous integration resources for your developers.</p></li><li><p>Get updates for certain packages on a regular interval, instead of right away.</p></li><li><p>Reduce Renovate bot PR notifications during the day.</p></li></ul><p>You can customize the scheduler with a specific timezone and the schedule cadence. For instance you can have Renovate to run every 2 Tuesdays with the following configuration:</p><p><code>  &#8220;schedule&#8221;: [</code></p><p><code>    &#8220;on the 1st and 3rd day instance on Tuesday&#8221;</code></p><p><code>  ]</code></p><p></p><p>This tool is fully customizable. For instance you can configure when to update specific dependencies. <a href="https://arc.net/l/quote/muolsqqy">Take a look the scheduling documentation</a>.</p><p>Below you can see a diagram with the overview of how Renovate is configured and how it works as a Github App.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!-rbF!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff8dc1ba3-b864-4d93-ae44-d72d9c5fcaff_7819x5073.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!-rbF!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff8dc1ba3-b864-4d93-ae44-d72d9c5fcaff_7819x5073.png 424w, https://substackcdn.com/image/fetch/$s_!-rbF!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff8dc1ba3-b864-4d93-ae44-d72d9c5fcaff_7819x5073.png 848w, https://substackcdn.com/image/fetch/$s_!-rbF!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff8dc1ba3-b864-4d93-ae44-d72d9c5fcaff_7819x5073.png 1272w, https://substackcdn.com/image/fetch/$s_!-rbF!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff8dc1ba3-b864-4d93-ae44-d72d9c5fcaff_7819x5073.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!-rbF!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff8dc1ba3-b864-4d93-ae44-d72d9c5fcaff_7819x5073.png" width="728" height="472.5" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/f8dc1ba3-b864-4d93-ae44-d72d9c5fcaff_7819x5073.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:945,&quot;width&quot;:1456,&quot;resizeWidth&quot;:728,&quot;bytes&quot;:1504955,&quot;alt&quot;:&quot;Renovate Workflow&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.deeplifelearning.com/i/177091282?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff8dc1ba3-b864-4d93-ae44-d72d9c5fcaff_7819x5073.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="Renovate Workflow" title="Renovate Workflow" srcset="https://substackcdn.com/image/fetch/$s_!-rbF!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff8dc1ba3-b864-4d93-ae44-d72d9c5fcaff_7819x5073.png 424w, https://substackcdn.com/image/fetch/$s_!-rbF!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff8dc1ba3-b864-4d93-ae44-d72d9c5fcaff_7819x5073.png 848w, https://substackcdn.com/image/fetch/$s_!-rbF!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff8dc1ba3-b864-4d93-ae44-d72d9c5fcaff_7819x5073.png 1272w, https://substackcdn.com/image/fetch/$s_!-rbF!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff8dc1ba3-b864-4d93-ae44-d72d9c5fcaff_7819x5073.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image buttonBase-GK1x3M"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image buttonBase-GK1x3M"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">Renovate Workflow</figcaption></figure></div><p></p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://blog.x504.dev/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://blog.x504.dev/subscribe?"><span>Subscribe now</span></a></p><p></p><h2>Features</h2><p>Renovate can provide updates for most popular languages, platforms, and registries including: npm, Java, Python, .NET, Scala, Ruby, Go, Docker and more. Supports over <a href="https://docs.renovatebot.com/modules/manager/">90 different package managers</a>.</p><p>Renovate updates code repositories on the following platforms: GitHub, GitLab, Bitbucket, Azure DevOps, AWS Code Commit, Gitea, Forgejo, Gerrit (experimental)</p><p>In a nutshell what Renovate does:</p><ul><li><p>Delivers update PRs directly to your repo</p><ul><li><p>Relevant package files are discovered automatically</p></li><li><p>Pull Requests automatically generated in your repo</p></li></ul></li><li><p>Provides useful information to help you decide which updates to accept (age, adoption, pass rates, merge confidence)</p></li><li><p>Highly configurable and flexible to fit in with your needs and repository standards</p></li><li><p>Largest collection of languages and platforms (listed below)</p></li><li><p>Connects with private repositories and package registries</p><p></p></li></ul><h2>Tips and how to extend Renovate</h2><p>Finally I would like to provide my 5 cents on how I have extended this great tool and some tweaks that have worked for me.</p><ul><li><p>Use a central repository to define a configuration for a group of repositories. For instance define all the configurations related to Terraform modules in a central repository. It will save you time and a lot of Pull Requests, believe me, specially when you manage a high number of Terraform modules inside your organization.</p><p></p></li><li><p>Use automerge when makes sense. When renovate runs it will open a huge list of Pull Requests (PRs). One way to reduce this &#8220;spam&#8220; of PRs is to enable automerge for packages with a minor version upgrade or when the change is in lower environments (not production).</p><p></p></li><li><p>When you manage modules inside your organization and you use Github Releases. Renovate will create PRs on those repositories that consume those modules. You can see how it is fully automated by default &#128578;.</p><p></p></li><li><p>Once Renovate is enabled, you can also access the UI provided by Mend.io to see the runs and have a more detailed view of what it is doing. You just need to go to </p><p><a href="https://developer.mend.io/">https://developer.mend.io/</a> and login with your Version Control account, let&#8217;s say Github.</p></li></ul><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!jdqH!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffbf375a2-8e77-41c0-851a-4c94de375a41_2602x816.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!jdqH!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffbf375a2-8e77-41c0-851a-4c94de375a41_2602x816.png 424w, https://substackcdn.com/image/fetch/$s_!jdqH!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffbf375a2-8e77-41c0-851a-4c94de375a41_2602x816.png 848w, https://substackcdn.com/image/fetch/$s_!jdqH!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffbf375a2-8e77-41c0-851a-4c94de375a41_2602x816.png 1272w, https://substackcdn.com/image/fetch/$s_!jdqH!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffbf375a2-8e77-41c0-851a-4c94de375a41_2602x816.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!jdqH!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffbf375a2-8e77-41c0-851a-4c94de375a41_2602x816.png" width="1456" height="457" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/fbf375a2-8e77-41c0-851a-4c94de375a41_2602x816.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:457,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:121745,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.deeplifelearning.com/i/177091282?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffbf375a2-8e77-41c0-851a-4c94de375a41_2602x816.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!jdqH!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffbf375a2-8e77-41c0-851a-4c94de375a41_2602x816.png 424w, https://substackcdn.com/image/fetch/$s_!jdqH!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffbf375a2-8e77-41c0-851a-4c94de375a41_2602x816.png 848w, https://substackcdn.com/image/fetch/$s_!jdqH!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffbf375a2-8e77-41c0-851a-4c94de375a41_2602x816.png 1272w, https://substackcdn.com/image/fetch/$s_!jdqH!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffbf375a2-8e77-41c0-851a-4c94de375a41_2602x816.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image buttonBase-GK1x3M"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image buttonBase-GK1x3M"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!-W0e!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0aaf511e-05eb-4d84-a560-cec96a54ccf1_2336x1186.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!-W0e!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0aaf511e-05eb-4d84-a560-cec96a54ccf1_2336x1186.png 424w, https://substackcdn.com/image/fetch/$s_!-W0e!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0aaf511e-05eb-4d84-a560-cec96a54ccf1_2336x1186.png 848w, https://substackcdn.com/image/fetch/$s_!-W0e!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0aaf511e-05eb-4d84-a560-cec96a54ccf1_2336x1186.png 1272w, https://substackcdn.com/image/fetch/$s_!-W0e!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0aaf511e-05eb-4d84-a560-cec96a54ccf1_2336x1186.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!-W0e!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0aaf511e-05eb-4d84-a560-cec96a54ccf1_2336x1186.png" width="1456" height="739" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/0aaf511e-05eb-4d84-a560-cec96a54ccf1_2336x1186.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:739,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:252455,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.deeplifelearning.com/i/177091282?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0aaf511e-05eb-4d84-a560-cec96a54ccf1_2336x1186.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!-W0e!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0aaf511e-05eb-4d84-a560-cec96a54ccf1_2336x1186.png 424w, https://substackcdn.com/image/fetch/$s_!-W0e!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0aaf511e-05eb-4d84-a560-cec96a54ccf1_2336x1186.png 848w, https://substackcdn.com/image/fetch/$s_!-W0e!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0aaf511e-05eb-4d84-a560-cec96a54ccf1_2336x1186.png 1272w, https://substackcdn.com/image/fetch/$s_!-W0e!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0aaf511e-05eb-4d84-a560-cec96a54ccf1_2336x1186.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image buttonBase-GK1x3M"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image buttonBase-GK1x3M"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p></p><ul><li><p>Additionally you can download the <a href="https://github.com/renovatebot/renovate">CLI</a> and run it locally for troubleshooting, for instance using the <strong>&#8212;dry-run</strong> flag.</p></li></ul><p><code>renovate --dry-run</code></p><p></p><p></p><p>Enjoy it &#127875; !</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://blog.x504.dev/p/update-your-damn-dependencies?utm_source=substack&utm_medium=email&utm_content=share&action=share&quot;,&quot;text&quot;:&quot;Share&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://blog.x504.dev/p/update-your-damn-dependencies?utm_source=substack&utm_medium=email&utm_content=share&action=share"><span>Share</span></a></p><p></p><p></p><p></p>]]></content:encoded></item><item><title><![CDATA[Google’s Update Ruined My Phone—Here’s How I Fixed It]]></title><description><![CDATA[About Google Fiasco on owners of Pixel 4a devices]]></description><link>https://blog.x504.dev/p/googles-update-ruined-my-phoneheres</link><guid isPermaLink="false">https://blog.x504.dev/p/googles-update-ruined-my-phoneheres</guid><dc:creator><![CDATA[x504]]></dc:creator><pubDate>Sun, 02 Feb 2025 08:33:00 GMT</pubDate><enclosure url="https://substack-post-media.s3.amazonaws.com/public/images/265e9616-68bf-4426-a9fb-f6f942ccc38b_449x220.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!uIbl!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4c97bc1b-64ad-4f63-a122-bd6cd13ce260_449x220.jpeg" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!uIbl!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4c97bc1b-64ad-4f63-a122-bd6cd13ce260_449x220.jpeg 424w, https://substackcdn.com/image/fetch/$s_!uIbl!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4c97bc1b-64ad-4f63-a122-bd6cd13ce260_449x220.jpeg 848w, https://substackcdn.com/image/fetch/$s_!uIbl!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4c97bc1b-64ad-4f63-a122-bd6cd13ce260_449x220.jpeg 1272w, https://substackcdn.com/image/fetch/$s_!uIbl!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4c97bc1b-64ad-4f63-a122-bd6cd13ce260_449x220.jpeg 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!uIbl!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4c97bc1b-64ad-4f63-a122-bd6cd13ce260_449x220.jpeg" width="553" height="270.9576837416481" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/4c97bc1b-64ad-4f63-a122-bd6cd13ce260_449x220.jpeg&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:220,&quot;width&quot;:449,&quot;resizeWidth&quot;:553,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;Castigo en bolsa a Google por el fiasco de su inteligencia artificial&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="Castigo en bolsa a Google por el fiasco de su inteligencia artificial" title="Castigo en bolsa a Google por el fiasco de su inteligencia artificial" srcset="https://substackcdn.com/image/fetch/$s_!uIbl!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4c97bc1b-64ad-4f63-a122-bd6cd13ce260_449x220.jpeg 424w, https://substackcdn.com/image/fetch/$s_!uIbl!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4c97bc1b-64ad-4f63-a122-bd6cd13ce260_449x220.jpeg 848w, https://substackcdn.com/image/fetch/$s_!uIbl!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4c97bc1b-64ad-4f63-a122-bd6cd13ce260_449x220.jpeg 1272w, https://substackcdn.com/image/fetch/$s_!uIbl!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4c97bc1b-64ad-4f63-a122-bd6cd13ce260_449x220.jpeg 1456w" sizes="100vw" fetchpriority="high"></picture><div></div></div></a></figure></div><p>A few weeks ago, I noticed a decrease in the battery performance of my Google Pixel 4a. I didn't have time to investigate further, but while the battery used to last over 24 hours, I now had to recharge my phone just 2 or 3 hours after a full charge. <strong>Really</strong>?. I knew something was going one, perhaps my phone that I have for more than 3 years was too old and need a replacement &#129300;.</p><p>But I decided to investigate a bit more and it took me few seconds to realize I was not the only one with that problem recently. <em>My problem was basically in the news!</em>.</p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://blog.x504.dev/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Thanks for reading Deep Life Learning! Subscribe for free to receive new posts and support my work.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><p>Basically what happened is that in <em><strong>January</strong></em> of this year, Google launched the &#8220;<a href="https://support.google.com/pixelphone/answer/15701861">Pixel 4a Battery Performance Program</a>&#8220;.</p><p></p><blockquote><p><em>Google has determined that certain Pixel 4a phones require a software update to improve the stability of their battery&#8217;s performance. An automatic update would reduce battery life and charging performance for some "Impacted Devices." Affected customers had one year to choose from three options: sending in their phone for a battery replacement, receiving $50 (or the local equivalent), or getting $100 in Google Store credit toward a new Pixel phone. The support document did not mention any safety or hazard concerns.</em></p></blockquote><p></p><p>I am not going into the details. There are good articles out there expanding the information. I recommend specifically <a href="https://arstechnica.com/gadgets/2025/01/google-pixel-4as-ruinous-battery-performance-update-is-a-bewildering-mess/">this</a> one who said they reach out directly to Google about this problem and they tried to get answers.</p><p>I am just listing Google&#8217;s response from the mentioned article:</p><ul><li><p>It seems to have been built by a Google engineer "on their personal machine, not the proper buildsystem."</p></li><li><p>There is no source provided, as would normally be required of a Linux kernel build, though it may only need to be provided on request under the GNU General Public License.</p></li><li><p>The maximum charge voltage of certain battery profiles changes from 4.44 volts to 3.95, which would mean batteries cannot charge to anywhere near their former potential.</p></li><li><p>There are two main battery profiles, with distinct "ATL" and "LSN" markers; Martin suggests they relate to <a href="https://en.wikipedia.org/wiki/ATL_(company)">Amperex Technology Limited</a> and <a href="https://en.lishen.com.cn/">Lishen</a>, manufacturers of battery cells.</p></li><li><p>LSN-tagged batteries assigned the "debug" profile can see capacity reduced from 3,080 milliamp hours (mAh) to 1,539 mAh.</p></li></ul><p></p><p>To me, this is a fiasco from Google, forcing users to update phones that were working perfectly. <a href="https://www.theguardian.com/technology/2017/dec/21/apple-admits-slowing-older-iphones-because-of-flagging-batteries">We've seen a similar situation with Apple in the past</a>.</p><p></p><h3>Grapehene OS (Open Source) to the Rescue</h3><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!uRpK!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd5183505-293c-4a09-b082-74b13899638c_500x500.jpeg" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!uRpK!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd5183505-293c-4a09-b082-74b13899638c_500x500.jpeg 424w, https://substackcdn.com/image/fetch/$s_!uRpK!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd5183505-293c-4a09-b082-74b13899638c_500x500.jpeg 848w, https://substackcdn.com/image/fetch/$s_!uRpK!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd5183505-293c-4a09-b082-74b13899638c_500x500.jpeg 1272w, https://substackcdn.com/image/fetch/$s_!uRpK!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd5183505-293c-4a09-b082-74b13899638c_500x500.jpeg 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!uRpK!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd5183505-293c-4a09-b082-74b13899638c_500x500.jpeg" width="258" height="258" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/d5183505-293c-4a09-b082-74b13899638c_500x500.jpeg&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:500,&quot;width&quot;:500,&quot;resizeWidth&quot;:258,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;Embracing Change: My Journey from iPhone to Graphene OS (Part 1) | by  Justin Jones | Medium&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="Embracing Change: My Journey from iPhone to Graphene OS (Part 1) | by  Justin Jones | Medium" title="Embracing Change: My Journey from iPhone to Graphene OS (Part 1) | by  Justin Jones | Medium" srcset="https://substackcdn.com/image/fetch/$s_!uRpK!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd5183505-293c-4a09-b082-74b13899638c_500x500.jpeg 424w, https://substackcdn.com/image/fetch/$s_!uRpK!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd5183505-293c-4a09-b082-74b13899638c_500x500.jpeg 848w, https://substackcdn.com/image/fetch/$s_!uRpK!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd5183505-293c-4a09-b082-74b13899638c_500x500.jpeg 1272w, https://substackcdn.com/image/fetch/$s_!uRpK!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd5183505-293c-4a09-b082-74b13899638c_500x500.jpeg 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image buttonBase-GK1x3M"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image buttonBase-GK1x3M"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>I didn't give up. After a few hours of research, I decided to replace my phone's operating system with <a href="https://grapheneos.org/#grapheneos">GrapheneOS</a>, and I couldn't be happier! &#128515;</p><p>It is a privacy and security focused mobile OS with Android app compatibility developed as a non-profit <a href="https://grapheneos.org/source">open source</a> project.</p><p>I will leave some remarks about my transition to Graphene:</p><ul><li><p><strong>No Google apps or services:</strong> If you want and no need any Google apps you can have an Android phone without it. GrapheneOS will never include either Google Play services or another implementation of Google services like microG. Perhaps, <strong>it is still possible to install Google Play services</strong> and you can install and use any app from the store. On Graphene it is done by a set of fully sandboxed apps without special privileges via our <a href="https://grapheneos.org/usage#sandboxed-google-play">sandboxed Google Play compatibility layer</a>.</p></li><li><p><strong>No passive listening services:</strong> You won&#8217;t have those apps which continuously monitor for wake words and process conversations to offer recommendations</p></li><li><p><strong>More battery life:</strong> The most important thing is that the problem caused by Google's fiasco is gone, and the battery now performs just as it did before the update. Plus, <em><strong>without any passive listening services</strong></em>, the battery lasts even longer!.</p></li><li><p><strong>Bank&#8217; apps:</strong> They are a bit problematic to make them run in Graphene. It's likely to work but there's no guarantee. <a href="https://arc.net/l/quote/jjkhfxer">There is a list of Banking Applications Compatibility with GrapheneOS</a>. Check this out if this is very important for you!. <em><strong>I use 3 or 4 bank&#8217;s apps and 2 of them didn&#8217;t work. Not a big deal for me but worth to mention.</strong></em></p></li><li><p><strong>End Of Life support:</strong> For the Google Pixel 4a, Graphene OS does not provided any more firmware or driver security updates, and receive extended support from GrapheneOS via a legacy branch based on Android 13 with only the Android Open Source Project security backports, certain other security patches, and other minimal changes to keep them working. <em><strong>Not a big deal for me</strong></em>, what I have now is way better than before shipped by Google originally on my Pixel. <a href="https://grapheneos.org/faq#supported-devices">Check out the list of supported devices on Graphene OS.</a></p><p></p></li></ul><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://blog.x504.dev/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Thanks for reading Deep Life Learning! Subscribe for free to receive new posts and support my work.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><p></p><h3>Conclusions</h3><p>What started as a frustrating experience turned into an opportunity to take full control of my device. I discovered a better, more secure, and privacy-respecting alternative &#9829;&#65039;. My Pixel 4a now runs smoother and battery lasts longer.</p><p></p><p></p><p></p><p></p>]]></content:encoded></item><item><title><![CDATA[Challenges on Accelerating ML Inference on an Edge device]]></title><description><![CDATA[Recommended techniques for deploying AI at the edge]]></description><link>https://blog.x504.dev/p/challenges-on-accelerating-ml-inference</link><guid isPermaLink="false">https://blog.x504.dev/p/challenges-on-accelerating-ml-inference</guid><dc:creator><![CDATA[x504]]></dc:creator><pubDate>Fri, 24 Jan 2025 09:23:43 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!jT3I!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F009cd548-9d5c-4cf9-922a-f428eb62142b_3133x2318.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>In 1965 Intel co-founder Gordon Moore published a paper where he predicted that the number of transistors on an integrated circuit will double every 10 years. Two years later, he revised his prediction to doubling every two years. This is what we know today as the <strong>Moore's Law</strong> and its grounded in an emerging trend, has served as a guiding principle for the semiconductor industry for nearly 60 years.</p><p>The law has an inevitable limit. You can continue making something smaller and smaller...but only up to a certain point. Then another ways of innovation are required to make more powerful and optimal processors.</p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://blog.x504.dev/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Thanks for reading Deep Life Learning! Subscribe for free to receive new posts and support my work.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!jT3I!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F009cd548-9d5c-4cf9-922a-f428eb62142b_3133x2318.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!jT3I!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F009cd548-9d5c-4cf9-922a-f428eb62142b_3133x2318.png 424w, https://substackcdn.com/image/fetch/$s_!jT3I!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F009cd548-9d5c-4cf9-922a-f428eb62142b_3133x2318.png 848w, https://substackcdn.com/image/fetch/$s_!jT3I!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F009cd548-9d5c-4cf9-922a-f428eb62142b_3133x2318.png 1272w, https://substackcdn.com/image/fetch/$s_!jT3I!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F009cd548-9d5c-4cf9-922a-f428eb62142b_3133x2318.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!jT3I!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F009cd548-9d5c-4cf9-922a-f428eb62142b_3133x2318.png" width="672" height="497.0769230769231" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/009cd548-9d5c-4cf9-922a-f428eb62142b_3133x2318.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1077,&quot;width&quot;:1456,&quot;resizeWidth&quot;:672,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;Moore's law - Wikipedia&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="Moore's law - Wikipedia" title="Moore's law - Wikipedia" srcset="https://substackcdn.com/image/fetch/$s_!jT3I!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F009cd548-9d5c-4cf9-922a-f428eb62142b_3133x2318.png 424w, https://substackcdn.com/image/fetch/$s_!jT3I!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F009cd548-9d5c-4cf9-922a-f428eb62142b_3133x2318.png 848w, https://substackcdn.com/image/fetch/$s_!jT3I!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F009cd548-9d5c-4cf9-922a-f428eb62142b_3133x2318.png 1272w, https://substackcdn.com/image/fetch/$s_!jT3I!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F009cd548-9d5c-4cf9-922a-f428eb62142b_3133x2318.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image buttonBase-GK1x3M"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image buttonBase-GK1x3M"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Over the years, the demand of more compute resources has been undeniable. With the explosion of what we know today as the internet in the 90's, triggered a surge in the volume of digital data. Major companies like google realize that they could analyze the data using Big data techniques and uncovering insights into user behavior and digital patterns. They have been using this information for optimize their search engines and drive data-driven decision-making. </p><p>With a vast amount of data and the nature of machine learning algorithms requiring a huge amount of computing that a general-purpose CPU can not supply. This poses a problem to companies doing Machine Learning and Big Data analysis in the early stages. </p><p>In the 1990s, engineers created a specialized compute unit called the GPU (graphics processing unit) to improve video game graphics. Today, GPU cloud servers are used for many computational tasks, including computer clusters, artificial intelligence systems, and deep learning, to enhance the performance of parallel systems. The GPU presented a new paradigm on parallel computing architecture. It was presented as it could run simultaneous execution of two or more parts of a program. This approach combined multiple smaller computers with large memory banks and high-speed processors to form a single, high-performance supercomputer.</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!nGTq!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8866f6c8-f902-4ac8-94fb-04652755352f_480x173.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!nGTq!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8866f6c8-f902-4ac8-94fb-04652755352f_480x173.png 424w, https://substackcdn.com/image/fetch/$s_!nGTq!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8866f6c8-f902-4ac8-94fb-04652755352f_480x173.png 848w, https://substackcdn.com/image/fetch/$s_!nGTq!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8866f6c8-f902-4ac8-94fb-04652755352f_480x173.png 1272w, https://substackcdn.com/image/fetch/$s_!nGTq!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8866f6c8-f902-4ac8-94fb-04652755352f_480x173.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!nGTq!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8866f6c8-f902-4ac8-94fb-04652755352f_480x173.png" width="480" height="173" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/8866f6c8-f902-4ac8-94fb-04652755352f_480x173.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:173,&quot;width&quot;:480,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:16990,&quot;alt&quot;:&quot;Left: CPU architecture; right: GPU architecture. Source: https://www.omnisci.com/technical-glossary/cpu-vs-gpu.&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="Left: CPU architecture; right: GPU architecture. Source: https://www.omnisci.com/technical-glossary/cpu-vs-gpu." title="Left: CPU architecture; right: GPU architecture. Source: https://www.omnisci.com/technical-glossary/cpu-vs-gpu." srcset="https://substackcdn.com/image/fetch/$s_!nGTq!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8866f6c8-f902-4ac8-94fb-04652755352f_480x173.png 424w, https://substackcdn.com/image/fetch/$s_!nGTq!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8866f6c8-f902-4ac8-94fb-04652755352f_480x173.png 848w, https://substackcdn.com/image/fetch/$s_!nGTq!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8866f6c8-f902-4ac8-94fb-04652755352f_480x173.png 1272w, https://substackcdn.com/image/fetch/$s_!nGTq!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8866f6c8-f902-4ac8-94fb-04652755352f_480x173.png 1456w" sizes="100vw"></picture><div></div></div></a><figcaption class="image-caption">Left: CPU architecture; right: GPU architecture. Source: https://www.omnisci.com/technical-glossary/cpu-vs-gpu.</figcaption></figure></div><p>GPUs are good at doing lots of simple computations in parallel. This fits perfectly with the workload required for training neural networks like Convolutional Neural Networks (CNN).</p><p>Today, there are many of GPU vendors. Moreover companies had created their own custom hardware for optimize AI inference. One example, is the Facebook's hardware platform. The Facebook Zion is comprised of eight CPUs and eight accelerators. The module is disaggregated insofar as the server CPUs are in modular sleds and the accelerators sit in another modular system. The Zion system components are show in the picture below.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Km0-!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F44fa39a3-217d-4685-a4c1-97ca0e67631b_800x533.jpeg" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Km0-!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F44fa39a3-217d-4685-a4c1-97ca0e67631b_800x533.jpeg 424w, https://substackcdn.com/image/fetch/$s_!Km0-!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F44fa39a3-217d-4685-a4c1-97ca0e67631b_800x533.jpeg 848w, https://substackcdn.com/image/fetch/$s_!Km0-!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F44fa39a3-217d-4685-a4c1-97ca0e67631b_800x533.jpeg 1272w, https://substackcdn.com/image/fetch/$s_!Km0-!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F44fa39a3-217d-4685-a4c1-97ca0e67631b_800x533.jpeg 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Km0-!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F44fa39a3-217d-4685-a4c1-97ca0e67631b_800x533.jpeg" width="538" height="358.4425" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/44fa39a3-217d-4685-a4c1-97ca0e67631b_800x533.jpeg&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:533,&quot;width&quot;:800,&quot;resizeWidth&quot;:538,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;Facebook Zion System Components&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="Facebook Zion System Components" title="Facebook Zion System Components" srcset="https://substackcdn.com/image/fetch/$s_!Km0-!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F44fa39a3-217d-4685-a4c1-97ca0e67631b_800x533.jpeg 424w, https://substackcdn.com/image/fetch/$s_!Km0-!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F44fa39a3-217d-4685-a4c1-97ca0e67631b_800x533.jpeg 848w, https://substackcdn.com/image/fetch/$s_!Km0-!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F44fa39a3-217d-4685-a4c1-97ca0e67631b_800x533.jpeg 1272w, https://substackcdn.com/image/fetch/$s_!Km0-!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F44fa39a3-217d-4685-a4c1-97ca0e67631b_800x533.jpeg 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image buttonBase-GK1x3M"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image buttonBase-GK1x3M"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">Facebook Zion System Components</figcaption></figure></div><p>This is perfectly fine in cloud environments, where you have the possibility to choose the architecture, capacity and model of CPUs and GPUs achieving a homogeneous stack for training and inference Machine learning pipelines. However, moving ML inference and training to the edge introduces several new challenges. </p><p>In the following section, I will discuss these challenges in detail and provide practical recommendations for effective AI deployment at the edge.</p><p></p><h2>AI at the Edge</h2><p>The main idea of running Machine Learning at the edge is to reduce latency on the output. Moreover, there are cases where the devices deployed in the field does not have a reliable internet connection and inference must happens on the device without depending on the internet. One example of AI at edge is the Iphone feature to unlock your Iphone with your face as an unique identity key. </p><p></p><blockquote><p>You don't want the users end up in a situation that they can't get access to their phones because there is not internet connection. Moreover the capture of the image (your face), converted into the inputs for the AI model and the inference must happen really fast.</p></blockquote><p></p><p>Engineers have worked to overcome the challenges of enabling AI at the edge. For example, the iPhone's face unlock feature benefits from Apple's AI ecosystem. Since 2017, Apple has included its own mobile GPU, simplifying development for engineers by providing a homogeneous architecture when deploying apps to iPhones.</p><p>The Android ecosystem presents a different scenario. There are over 25 mobile chipset vendors which each mixes and matches its own custom-design components. With multiple chip vendors producing CPUs and GPUs for Android devices, the ecosystem is highly fragmented. Engineers aiming to deploy AI at the edge face significant challenges in targeting the various architectures.</p><p><strong><a href="https://www.vulkan.org/">Vulkan</a></strong> which is a low-overhead, cross-platform API for high-performance 3D graphics and is a successor to OpenGL and OpenGL ES, aims to provide a layer abstraction to gain control of the stack. Today, early adoption of <em><strong>Vulkan</strong></em> is limited but growing over the years.</p><p>This is the challenge with vendor diversity. A holistic approach is to develop ML models capable of running effective inference using only CPUs. This eliminates the need to ensure the model performs well across multiple GPU architectures. However, relying solely on CPUs introduces its own challenges, requiring significant software-level optimizations to make the model more efficient.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://blog.x504.dev/p/challenges-on-accelerating-ml-inference?utm_source=substack&utm_medium=email&utm_content=share&action=share&quot;,&quot;text&quot;:&quot;Share&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://blog.x504.dev/p/challenges-on-accelerating-ml-inference?utm_source=substack&utm_medium=email&utm_content=share&action=share"><span>Share</span></a></p><p></p><h2>Techniques for AI at  the Edge</h2><p>Engineers also face implicit challenges due to the constraints of IoT devices. These devices have limited CPU, GPU, and memory resources, which makes certain techniques necessary to improve AI performance at the edge. The following techniques are recommended:</p><ul><li><p><strong>Data parallelism</strong>: It is common to split the data and send them in parallel to multiple CPUs/GPUs to make the inference faster.</p></li><li><p><strong>Model parallelism</strong>: Some ML frameworks allow you to split the model having each CPU/GPU core process its own part. This approach is more complex and not all frameworks and hardware vendors allow it.</p></li><li><p><strong>Heavy initialization of ML/DL model</strong>: The recommendation is to perform initialization <strong>once</strong> per process/thread and reuse them for running inference.</p></li><li><p> <strong>Under-utilization</strong>: It is common to land in a situation that the tasks handled by the CPU could take 100% of its capacity, while underutilized the GPU.</p></li><li><p><strong>Out-of-order outputs</strong>: When an order of the outputs are required in a parallelized system, then an extra task is required like indexing and reordering.</p></li><li><p><strong>Multiprocessing</strong>: Several languages for performing Machine Learning allow you to use multiprocessing techniques to take advantage of parallelism with GPUs. It is worth to mention that not all Deep Learning frameworks supports multiprocessing.</p></li><li><p><strong>Training at edge</strong>: In some cases, the IoT device may need to learn from data, requiring both ML training and inference to occur on the constrained device. One common approach is to use a model with frozen weights and perform fine-tuning, which is less computationally demanding.</p></li><li><p><strong>Optimizations</strong>: Model architecture search, weight compression, quantization, algorithmic complexity reduction, increase of training data, refining features sets and micro-architecture specific performance.</p></li></ul><p></p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!CnCh!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1e934288-6c3b-41a3-b170-f596b1e13f3f_1200x665.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!CnCh!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1e934288-6c3b-41a3-b170-f596b1e13f3f_1200x665.png 424w, https://substackcdn.com/image/fetch/$s_!CnCh!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1e934288-6c3b-41a3-b170-f596b1e13f3f_1200x665.png 848w, https://substackcdn.com/image/fetch/$s_!CnCh!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1e934288-6c3b-41a3-b170-f596b1e13f3f_1200x665.png 1272w, https://substackcdn.com/image/fetch/$s_!CnCh!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1e934288-6c3b-41a3-b170-f596b1e13f3f_1200x665.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!CnCh!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1e934288-6c3b-41a3-b170-f596b1e13f3f_1200x665.png" width="544" height="301.46666666666664" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/1e934288-6c3b-41a3-b170-f596b1e13f3f_1200x665.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:665,&quot;width&quot;:1200,&quot;resizeWidth&quot;:544,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;Tiny Machine Learning: The Next AI Revolution | by Matthew Stewart, PhD |  Towards Data Science&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="Tiny Machine Learning: The Next AI Revolution | by Matthew Stewart, PhD |  Towards Data Science" title="Tiny Machine Learning: The Next AI Revolution | by Matthew Stewart, PhD |  Towards Data Science" srcset="https://substackcdn.com/image/fetch/$s_!CnCh!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1e934288-6c3b-41a3-b170-f596b1e13f3f_1200x665.png 424w, https://substackcdn.com/image/fetch/$s_!CnCh!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1e934288-6c3b-41a3-b170-f596b1e13f3f_1200x665.png 848w, https://substackcdn.com/image/fetch/$s_!CnCh!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1e934288-6c3b-41a3-b170-f596b1e13f3f_1200x665.png 1272w, https://substackcdn.com/image/fetch/$s_!CnCh!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1e934288-6c3b-41a3-b170-f596b1e13f3f_1200x665.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image buttonBase-GK1x3M"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image buttonBase-GK1x3M"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">TinyML with TensorFlow Lite</figcaption></figure></div><p></p><p>The growing importance of deep learning-based applications presents both exciting opportunities and complex design challenges at the edge. <strong><a href="https://www.edgeaifoundation.org/">TinyML</a>, </strong>for instance<strong>, </strong> is a new approach that simplifies the integration of AI at the edge, enabling applications where sending data to the cloud is impractical. Fortunately, hardware has advanced to the point where real-time analytics are now feasible. For instance, the Arm Cortex-M4 processor can perform more FFTs (Fast Fourier Transform) per second than the Pentium 4, while consuming significantly less power. Similar improvements in power and performance have been made in sensors and wireless communication. TinyML allows us to leverage these hardware advances to create innovative applications that were previously impossible.</p><p>To know more about TinyML and AI at the Edge, I recommend the following resources:</p><ul><li><p><a href="https://arxiv.org/html/2403.19076v2">Tiny Machine Learning: Progress and Futures</a></p></li><li><p><a href="https://edgeimpulse.com/">Edge Impulse</a></p></li><li><p><a href="https://arxiv.org/abs/2212.03332">Edge Impulse: An MLOps Platform for Tiny Machine Learning</a></p></li></ul><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://blog.x504.dev/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Thanks for reading Deep Life Learning! Subscribe for free to receive new posts and support my work.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div>]]></content:encoded></item><item><title><![CDATA[Why It Might Be Time to Rethink Using Cosine Similarity]]></title><description><![CDATA[Last year, researchers from Netflix released a study on the nuances of using cosine distance in recommendation systems.]]></description><link>https://blog.x504.dev/p/why-it-might-be-time-to-rethink-using</link><guid isPermaLink="false">https://blog.x504.dev/p/why-it-might-be-time-to-rethink-using</guid><dc:creator><![CDATA[x504]]></dc:creator><pubDate>Sat, 18 Jan 2025 22:02:51 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!XrBh!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbd388787-8937-4ef9-be9f-b342a3720abc_450x408.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Last year, researchers from Netflix released a <a href="https://arxiv.org/pdf/2403.05440v1">study</a> on the nuances of using cosine distance in recommendation systems. Their experiments revealed underlying issues with cosine similarity as a metric that can lead to arbitrary and meaningless results.</p><p>Cosine similarity measures the cosine of the angle between two vectors or, equivalently, the dot product of their normalized forms. It has proven useful in various applications, such as recommender systems and NLP tasks. However it has been proven to have poor results in certain scenarios.</p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://blog.x504.dev/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Thanks for reading Deep Life Learning! Subscribe for free to receive new posts and support my work.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><p>Using cosine similarity as a training objective for machine learning models is valid and mathematically sound. It combines two fundamental operations in deep learning: dot product and normalization. The trouble arises when we push it beyond its intended scope, particularly in cases where the objective function used in model training isn't cosine similarity. Which is usually the case.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!XrBh!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbd388787-8937-4ef9-be9f-b342a3720abc_450x408.jpeg" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!XrBh!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbd388787-8937-4ef9-be9f-b342a3720abc_450x408.jpeg 424w, https://substackcdn.com/image/fetch/$s_!XrBh!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbd388787-8937-4ef9-be9f-b342a3720abc_450x408.jpeg 848w, https://substackcdn.com/image/fetch/$s_!XrBh!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbd388787-8937-4ef9-be9f-b342a3720abc_450x408.jpeg 1272w, https://substackcdn.com/image/fetch/$s_!XrBh!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbd388787-8937-4ef9-be9f-b342a3720abc_450x408.jpeg 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!XrBh!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbd388787-8937-4ef9-be9f-b342a3720abc_450x408.jpeg" width="450" height="408" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/bd388787-8937-4ef9-be9f-b342a3720abc_450x408.jpeg&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:408,&quot;width&quot;:450,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;Dragon Ball Z patrick - 3309846016&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="Dragon Ball Z patrick - 3309846016" title="Dragon Ball Z patrick - 3309846016" srcset="https://substackcdn.com/image/fetch/$s_!XrBh!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbd388787-8937-4ef9-be9f-b342a3720abc_450x408.jpeg 424w, https://substackcdn.com/image/fetch/$s_!XrBh!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbd388787-8937-4ef9-be9f-b342a3720abc_450x408.jpeg 848w, https://substackcdn.com/image/fetch/$s_!XrBh!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbd388787-8937-4ef9-be9f-b342a3720abc_450x408.jpeg 1272w, https://substackcdn.com/image/fetch/$s_!XrBh!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbd388787-8937-4ef9-be9f-b342a3720abc_450x408.jpeg 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image buttonBase-GK1x3M"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image buttonBase-GK1x3M"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">Source : <a href="https://cheezburger.com/3309846016/similarity">https://cheezburger.com/3309846016/similarity</a></figcaption></figure></div><p></p><p>It is easy to demonstrate, how sentences that are semantically similar will have poor result when calculating their cosine similarity. For instance let&#8217;s have as an example the following 3 sentences:</p><ol><li><p>&#8220;AI can make you rich.&#8221;</p></li><li><p>&#8220;AI can make you itch.&#8220;</p></li><li><p>&#8220;Mastering AI can fill your pockets.&#8220;</p></li></ol><p></p><p>Let&#8217;s calculate the cosine similarity between 1 and 2 and then 1 and 3. What do you expect as a result?. Semantically 1 and 3 are closer so let&#8217;s see.</p><p></p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!4pGW!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7f6a74fb-2046-4879-b82c-5f6e14a76687_2336x530.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!4pGW!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7f6a74fb-2046-4879-b82c-5f6e14a76687_2336x530.png 424w, https://substackcdn.com/image/fetch/$s_!4pGW!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7f6a74fb-2046-4879-b82c-5f6e14a76687_2336x530.png 848w, https://substackcdn.com/image/fetch/$s_!4pGW!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7f6a74fb-2046-4879-b82c-5f6e14a76687_2336x530.png 1272w, https://substackcdn.com/image/fetch/$s_!4pGW!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7f6a74fb-2046-4879-b82c-5f6e14a76687_2336x530.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!4pGW!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7f6a74fb-2046-4879-b82c-5f6e14a76687_2336x530.png" width="1456" height="330" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/7f6a74fb-2046-4879-b82c-5f6e14a76687_2336x530.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:330,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:113383,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!4pGW!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7f6a74fb-2046-4879-b82c-5f6e14a76687_2336x530.png 424w, https://substackcdn.com/image/fetch/$s_!4pGW!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7f6a74fb-2046-4879-b82c-5f6e14a76687_2336x530.png 848w, https://substackcdn.com/image/fetch/$s_!4pGW!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7f6a74fb-2046-4879-b82c-5f6e14a76687_2336x530.png 1272w, https://substackcdn.com/image/fetch/$s_!4pGW!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7f6a74fb-2046-4879-b82c-5f6e14a76687_2336x530.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a><figcaption class="image-caption"></figcaption></figure></div><p>Ah! The vector resulting from sentence (1) is closer to sentence (2) than to sentence (3). That&#8217;s likely not the desired outcome in an NLP pipeline or a recommendation system. This simple example demonstrates how cosine similarity can lead to unexpected results.</p><p>Cosine similarity is a quick fix for vector comparisons, as shown in the previous example. While it works and can be useful, in some cases&#8212;and I would argue in most cases&#8212;it masks deeper underlying issues.</p><p>So, what can we do about it? There are several alternatives, and it all comes down to one thing: testing, researching, and more testing! Below, I will outline possible solutions, but as you might already know, there&#8217;s no silver bullet. It&#8217;s all about experimenting and testing with your deep learning model and data.</p><ul><li><p>Train models directly with respect to cosine similarity.</p></li><li><p>Use LLM&#8217;s to guide the search, perhaps incorporate an<a href="https://blogs.nvidia.com/blog/what-is-agentic-ai/"> AI agentic approach</a>.</p></li><li><p>Use a different metric for comparison as the <a href="https://www.turing.com/kb/how-to-decide-perfect-distance-metric-for-machine-learning-model">Euclidean distance</a> or soft cosine similarity.</p></li><li><p>Clean and standardize text before embedding before using cosine similarity can help mitigate some of its issues.</p></li></ul><p></p><p></p><h3>Resources</h3><p>[1] <a href="https://arxiv.org/pdf/2403.05440v1">Is Cosine-Similarity of Embeddings Really About Similarity?</a></p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://blog.x504.dev/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Thanks for reading Deep Life Learning! Subscribe for free to receive new posts and support my work.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div>]]></content:encoded></item><item><title><![CDATA[Kubernetes 1.30 on EKS]]></title><description><![CDATA[What You Need to Know About AL2023]]></description><link>https://blog.x504.dev/p/kubernetes-130-on-eks</link><guid isPermaLink="false">https://blog.x504.dev/p/kubernetes-130-on-eks</guid><dc:creator><![CDATA[x504]]></dc:creator><pubDate>Wed, 08 Jan 2025 08:38:14 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!yIjU!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff2732ac3-8012-4711-b38f-e3d8656f3049_900x900.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Recently, I started began upgrading our <a href="https://aws.amazon.com/eks/">EKS</a> clusters to <a href="https://kubernetes.io/blog/2024/04/17/kubernetes-v1-30-release/">Kubernetes version 1.30</a>. With this version, any newly created managed node groups now default to using <strong><a href="https://arc.net/l/quote/bxvgzbbs">Amazon Linux 2023 (AL2023)</a></strong> as the node operating system. In contrast, <strong>Amazon Linux 2 (AL2)</strong> was the default for new node groups in earlier versions.</p><p>The Kubernetes release version 1.30 also named as <strong>Uwubernetes (released on April 2024) </strong>came with interesting changes and enhancements. Here I am highlighting those I think are the most important:</p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://blog.x504.dev/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Thanks for reading Deep Life Learning! Subscribe for free to receive new posts and support my work.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><ul><li><p><a href="https://github.com/kubernetes/enhancements/issues/1610">Container Resource-Based Pod Autoscaling</a></p></li><li><p><a href="https://github.com/kubernetes/enhancements/issues/3756">Robust VolumeManager reconstruction after kubelet restart</a></p></li><li><p><a href="https://github.com/kubernetes/enhancements/blob/master/keps/sig-scheduling/3521-pod-scheduling-readiness/README.md">Pod Scheduling Readiness</a></p></li></ul><p></p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!yIjU!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff2732ac3-8012-4711-b38f-e3d8656f3049_900x900.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!yIjU!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff2732ac3-8012-4711-b38f-e3d8656f3049_900x900.png 424w, https://substackcdn.com/image/fetch/$s_!yIjU!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff2732ac3-8012-4711-b38f-e3d8656f3049_900x900.png 848w, https://substackcdn.com/image/fetch/$s_!yIjU!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff2732ac3-8012-4711-b38f-e3d8656f3049_900x900.png 1272w, https://substackcdn.com/image/fetch/$s_!yIjU!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff2732ac3-8012-4711-b38f-e3d8656f3049_900x900.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!yIjU!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff2732ac3-8012-4711-b38f-e3d8656f3049_900x900.png" width="352" height="352" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/f2732ac3-8012-4711-b38f-e3d8656f3049_900x900.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:900,&quot;width&quot;:900,&quot;resizeWidth&quot;:352,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;Kubernetes v1.30 Uwubernetes logo&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="Kubernetes v1.30 Uwubernetes logo" title="Kubernetes v1.30 Uwubernetes logo" srcset="https://substackcdn.com/image/fetch/$s_!yIjU!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff2732ac3-8012-4711-b38f-e3d8656f3049_900x900.png 424w, https://substackcdn.com/image/fetch/$s_!yIjU!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff2732ac3-8012-4711-b38f-e3d8656f3049_900x900.png 848w, https://substackcdn.com/image/fetch/$s_!yIjU!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff2732ac3-8012-4711-b38f-e3d8656f3049_900x900.png 1272w, https://substackcdn.com/image/fetch/$s_!yIjU!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff2732ac3-8012-4711-b38f-e3d8656f3049_900x900.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image buttonBase-GK1x3M"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image buttonBase-GK1x3M"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>In this article, I won&#8217;t go into the details of the Kubernetes 1.30 release. Instead, my focus is to introduce and discuss the significant change in EKS (AWS Managed Kubernetes Service), where Amazon Linux 2023 (AL2023) has replaced Amazon Linux 2 (AL2) as the default operating system for managed node groups.</p><p></p><blockquote><p><strong>Note:</strong> If you prefer to continue using AL2, you can select it as the AMI type when creating a new node group.</p></blockquote><p></p><h2>What is Amazon Linux 2023 (AL2023)</h2><p>From AWS website.</p><blockquote><p>Amazon Linux 2023 (AL2023) is the next generation of Amazon Linux from Amazon Web Services (AWS). With AL2023, you can develop and run cloud and enterprise applications in a secure, stable, and high-performance runtime environment. Also you get an application environment that offers long-term support with access to the latest innovations in Linux. AL2023 is provided at no additional charge.</p></blockquote><p>In general terms, this operating system comes with enhancements for running Linux on the cloud which make it more faster and secured. If you want to know more in details the performance and operational optimizations, you will find useful this <a href="https://docs.aws.amazon.com/linux/al2023/ug/performance-optimizations.html">link</a>.</p><p>There is an extensive documentation as well about comparing AL2 and AL2023, check it out <a href="https://docs.aws.amazon.com/linux/al2023/ug/compare-with-al2.html">here</a>.</p><p>Finally, if you need to know what are the packages and new packages with their version that comes on the new AMI based on AL2023, check this other link <a href="https://docs.aws.amazon.com/linux/al2023/release-notes/new-packages.html">here</a>.</p><p>There is a lot to say about the transition from AL2 to AL2023, but on this article I am going to focus in a specific change that can affect your Kubernetes workloads when performing this migration.</p><p></p><h2>Containers and AL2023</h2><p>Before, let me quickly explain what is the Instance Metadata Service (IMDS). </p><p>This is a feature that provides metadata about an EC2 instance to the instance itself. This metadata includes details such as the instance ID, AMI ID, security group, and other configuration information. </p><p>IMDS also provides temporary credentials for accessing AWS services securely without embedding credentials in the application. Applications running on the instance can access IMDS via HTTP requests to a special local endpoint, 169.254.169.254.</p><p></p><h4>&#128148; The breaking change</h4><p><strong>AL2023 requires IMDSv2 by default</strong>. IMDSv2 has several benefits that help improve security posture. It uses a session-oriented authentication method that requires the creation of a secret token in a simple HTTP PUT request to start the session. A session's token can be valid for anywhere between 1 second and 6 hours.</p><p>For <strong>IMDSv2</strong>, the default hop count for managed node groups is set to 1. This means that <strong>containers won't have access to the node's credentials using IMDS</strong>.</p><p>Depending how you configured your workloads and in case they need access to the nodes&#8217;s credentials using IMDS then you will need to workaround this problem.</p><p>Following I show you different alternatives for solving this problem.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://blog.x504.dev/p/kubernetes-130-on-eks?utm_source=substack&utm_medium=email&utm_content=share&action=share&quot;,&quot;text&quot;:&quot;Share&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://blog.x504.dev/p/kubernetes-130-on-eks?utm_source=substack&utm_medium=email&utm_content=share&action=share"><span>Share</span></a></p><p></p><h4>&#128640; Alternatives to solve this problem</h4><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!8Ane!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5d8c7343-cee0-45df-b247-980074c83aed_633x140.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!8Ane!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5d8c7343-cee0-45df-b247-980074c83aed_633x140.png 424w, https://substackcdn.com/image/fetch/$s_!8Ane!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5d8c7343-cee0-45df-b247-980074c83aed_633x140.png 848w, https://substackcdn.com/image/fetch/$s_!8Ane!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5d8c7343-cee0-45df-b247-980074c83aed_633x140.png 1272w, https://substackcdn.com/image/fetch/$s_!8Ane!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5d8c7343-cee0-45df-b247-980074c83aed_633x140.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!8Ane!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5d8c7343-cee0-45df-b247-980074c83aed_633x140.png" width="633" height="140" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/5d8c7343-cee0-45df-b247-980074c83aed_633x140.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:140,&quot;width&quot;:633,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:33412,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!8Ane!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5d8c7343-cee0-45df-b247-980074c83aed_633x140.png 424w, https://substackcdn.com/image/fetch/$s_!8Ane!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5d8c7343-cee0-45df-b247-980074c83aed_633x140.png 848w, https://substackcdn.com/image/fetch/$s_!8Ane!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5d8c7343-cee0-45df-b247-980074c83aed_633x140.png 1272w, https://substackcdn.com/image/fetch/$s_!8Ane!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5d8c7343-cee0-45df-b247-980074c83aed_633x140.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><ol><li><p><strong>Use EKS Pod Identity</strong></p><p></p><p>In my opinion, the best way is to configure your workloads in Kubernetes using EKS Pod Identity. Basically you associate an IAM role with a Kubernetes Service Account and then you configure your workloads (pods) to use the service account. More information about it <a href="https://docs.aws.amazon.com/eks/latest/userguide/pod-identities.html">here</a>.</p><p></p></li><li><p><strong>Use a Launch template with HttpPutResponseHopLimit</strong></p><p></p><p>As mentioned before on this article, for IMDSv2 the the default hop count is set to 1. You can configure this hop limit to any value greater than 1 using a launch template for your EKS managed worker nodes on the <a href="https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-ec2-launchtemplate-metadataoptions.html#cfn-ec2-launchtemplate-metadataoptions-httpputresponsehoplimit">Launch Template Metadata Options</a>. For instance:</p><pre><code>{
  "HttpEndpoint" : String,
  "HttpProtocolIpv6" : String,
  <strong>"HttpPutResponseHopLimit" : 3,</strong>
  "HttpTokens" : String,
  "InstanceMetadataTags" : String
}</code></pre><p></p></li><li><p><strong>Configure instance metadata options for new instances</strong></p><p>Is it possible to set some default EC2 metadata settings at the AWS account level (per region) so any new EC2 instance will take the default settings. Keep in mind that you can override the default settings by specifying the setting at launch time of the EC2 instance.</p><p></p><p>Using the AWS CLI you can do this, for instance:</p><pre><code>aws ec2 modify-instance-metadata-defaults \
    --region us-east-1 \
    <strong>--http-put-response-hop-limit 2</strong></code></pre><p>Using Terraform you can do it like this:</p><pre><code>resource "aws_ec2_instance_metadata_defaults" "ec2_metadata_defaults" {
  <strong>http_put_response_hop_limit = 3</strong>
}</code></pre><p>  </p></li><li><p>Change instance metadata options on existing instances</p><p>In case you need to change the metadata option to an existing running instance. You can do it with the AWS CLI and it won&#8217;t required the instance to restart or be replaced at all. You can perform this change for instance like this:</p><pre><code>aws ec2 modify-instance-metadata-options --instance-id i-123456789 -<strong>-http-put-response-hop-limit 3</strong></code></pre></li></ol><p></p><p>Here are the alternatives available to address this situation. You might also be curious about which EC2 instances are still using IMDSv1 and whether they depend on this metadata version. Fortunately, AWS provides comprehensive documentation to guide you through this transition, which you can access <a href="https://chatgpt.com/c/6778ef33-cd14-8012-b305-e16722f3f4a9#">here</a>.</p><p></p><h2>Resources</h2><p>[1]  <a href="https://arc.net/l/quote/jmqxgpoh">Review release notes for Kubernetes versions on standard support</a></p><p>[2] <a href="https://arc.net/l/quote/vdofgieq">What is Amazon Linux 2023?</a></p><p>[3] <a href="https://arc.net/l/quote/yjvlmgrp">Performance and operational optimizations</a></p><p>[4] <a href="https://arc.net/l/quote/eirqnnlc">Comparing AL2 and AL2023</a></p><p>[5] <a href="https://arc.net/l/quote/nxjspoiq">New Packages in AL2023</a></p><p>[6] <a href="https://docs.aws.amazon.com/eks/latest/userguide/pod-identities.html">Learn how EKS Pod Identity grants pods access to AWS services</a></p><p>[7] <a href="https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-ec2-launchtemplate-metadataoptions.html#cfn-ec2-launchtemplate-metadataoptions-httpputresponsehoplimit">EC2 LaunchTemplate MetadataOptions</a></p><p>[8] <a href="https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/configuring-IMDS-new-instances.html">Configure instance metadata options for new instances</a></p><p>[9] <a href="https://arc.net/l/quote/urgvzbeg">Modify instance metadata options for existing instances</a></p><p>[10] <a href="https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/configuring-instance-metadata-options.html">Configure the Instance Metadata Service options</a></p><p>[11] <a href="https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ec2_instance_metadata_defaults">Terraform Resource: aws_ec2_instance_metadata_defaults</a></p><p>[12] <a href="https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/launch_template">Terraform Resource: aws_launch_template</a></p><p>[13] <a href="https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/configuring-instance-metadata-service.html#instance-metadata-transition-to-version-2">Transition to using Instance Metadata Service Version 2</a></p><p></p><p></p><p></p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://blog.x504.dev/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Thanks for reading Deep Life Learning! Subscribe for free to receive new posts and support my work.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div>]]></content:encoded></item><item><title><![CDATA[Improving RAG Pipelines with Hybrid Search]]></title><description><![CDATA[RAG optimization with Hybrid Search]]></description><link>https://blog.x504.dev/p/improving-rag-pipelines-with-hybrid</link><guid isPermaLink="false">https://blog.x504.dev/p/improving-rag-pipelines-with-hybrid</guid><dc:creator><![CDATA[x504]]></dc:creator><pubDate>Sun, 29 Dec 2024 11:57:56 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!nLQ7!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F22426e00-a0d7-407b-9fe2-25c40c027349_1326x745.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>In this article, I will demonstrate how to implement hybrid search within a RAG (Retrieval-Augmented Generation) pipeline to enhance the effectiveness of the retrieval phase.</p><p>I will be using <a href="https://github.com/milvus-io">Milvus</a> as a vector database and the <a href="https://arxiv.org/pdf/2402.03216">M3-Embedding</a> model for generating dense and sparse vectors embeddings.</p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://blog.x504.dev/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Thanks for reading Deep Life Learning! Subscribe for free to receive new posts and support my work.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><p>Let&#8217;s start with a short description of RAG.</p><h2>Short description of Retrieval Augmented Generation (RAG)</h2><p>RAG is a technique that emerged with the great evolution in the last years of Natural Language Generation (NLG) models. It integrates retrieval mechanisms with generative language models to improve output accuracy, effectively addressing the primary limitations of Large Language Models (LLMs).</p><p>Traditional NLG models, particularly sequence-to-sequence architectures, generate fluent and coherent text. However, these models depend heavily on training data and often face challenges in producing factually accurate or contextually relevant content for queries requiring knowledge beyond their training data, such as private data.</p><p>RAG is an emerging hybrid technique designed to address the limitations of pure generative models integrating two key components:</p><ul><li><p>A retrieval mechanism, which retrieves relevant documents or information from an external knowledge source.</p></li><li><p>A generative module, which processes this information to generate human-like text.</p><p></p></li></ul><p>This combination enables RAG architectures to generate fluent text while grounding their outputs in real-world, up-to-date data.</p><p></p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!nLQ7!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F22426e00-a0d7-407b-9fe2-25c40c027349_1326x745.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!nLQ7!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F22426e00-a0d7-407b-9fe2-25c40c027349_1326x745.png 424w, https://substackcdn.com/image/fetch/$s_!nLQ7!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F22426e00-a0d7-407b-9fe2-25c40c027349_1326x745.png 848w, https://substackcdn.com/image/fetch/$s_!nLQ7!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F22426e00-a0d7-407b-9fe2-25c40c027349_1326x745.png 1272w, https://substackcdn.com/image/fetch/$s_!nLQ7!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F22426e00-a0d7-407b-9fe2-25c40c027349_1326x745.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!nLQ7!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F22426e00-a0d7-407b-9fe2-25c40c027349_1326x745.png" width="1326" height="745" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/22426e00-a0d7-407b-9fe2-25c40c027349_1326x745.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:745,&quot;width&quot;:1326,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:70106,&quot;alt&quot;:&quot;Vanilla RAG pipeline&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="Vanilla RAG pipeline" title="Vanilla RAG pipeline" srcset="https://substackcdn.com/image/fetch/$s_!nLQ7!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F22426e00-a0d7-407b-9fe2-25c40c027349_1326x745.png 424w, https://substackcdn.com/image/fetch/$s_!nLQ7!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F22426e00-a0d7-407b-9fe2-25c40c027349_1326x745.png 848w, https://substackcdn.com/image/fetch/$s_!nLQ7!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F22426e00-a0d7-407b-9fe2-25c40c027349_1326x745.png 1272w, https://substackcdn.com/image/fetch/$s_!nLQ7!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F22426e00-a0d7-407b-9fe2-25c40c027349_1326x745.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image buttonBase-GK1x3M"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image buttonBase-GK1x3M"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">Vanilla RAG pipeline</figcaption></figure></div><p>Before I show the implementation of the hybrid search. let&#8217;s define the main components of it.</p><h2>Sparse Vectors</h2><p>Sparse vectors are used as a data representation in Natural Language Processing (NLP). Their main characteristic is that most of the elements are zero&#8212;keeping only what is more relevant in terms of the data representation. This allows sparse vectors to be more accurate when it comes to applications that require precise matching of keywords or sentences.</p><p>Common applications:</p><ul><li><p>Text analysis</p></li><li><p>Recommendation systems</p></li><li><p>Image processing </p></li></ul><p></p><p>Sparse vectors can be generated by for instance using the <a href="https://en.wikipedia.org/wiki/Okapi_BM25">BM25</a> method. It relies on the frequency of words in a document and does not attempt to comprehend the meaning of context of the words. It also required the computation of the entire corpus in advance.</p><p></p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!XGB5!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F05e76c7a-73aa-4b29-9c50-6abd09d70b1c_361x360.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!XGB5!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F05e76c7a-73aa-4b29-9c50-6abd09d70b1c_361x360.png 424w, https://substackcdn.com/image/fetch/$s_!XGB5!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F05e76c7a-73aa-4b29-9c50-6abd09d70b1c_361x360.png 848w, https://substackcdn.com/image/fetch/$s_!XGB5!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F05e76c7a-73aa-4b29-9c50-6abd09d70b1c_361x360.png 1272w, https://substackcdn.com/image/fetch/$s_!XGB5!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F05e76c7a-73aa-4b29-9c50-6abd09d70b1c_361x360.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!XGB5!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F05e76c7a-73aa-4b29-9c50-6abd09d70b1c_361x360.png" width="361" height="360" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/05e76c7a-73aa-4b29-9c50-6abd09d70b1c_361x360.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:360,&quot;width&quot;:361,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:20289,&quot;alt&quot;:&quot;Sparse Matrix&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="Sparse Matrix" title="Sparse Matrix" srcset="https://substackcdn.com/image/fetch/$s_!XGB5!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F05e76c7a-73aa-4b29-9c50-6abd09d70b1c_361x360.png 424w, https://substackcdn.com/image/fetch/$s_!XGB5!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F05e76c7a-73aa-4b29-9c50-6abd09d70b1c_361x360.png 848w, https://substackcdn.com/image/fetch/$s_!XGB5!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F05e76c7a-73aa-4b29-9c50-6abd09d70b1c_361x360.png 1272w, https://substackcdn.com/image/fetch/$s_!XGB5!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F05e76c7a-73aa-4b29-9c50-6abd09d70b1c_361x360.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image buttonBase-GK1x3M"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image buttonBase-GK1x3M"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">Example of a sparse Matrix</figcaption></figure></div><p></p><h2>Dense Vectors</h2><p>Dense vectors are a numerical representation of semantic meaning and they are ideal for capturing deep semantic relationships. Compared to sparse vectors, dense vectors encode more information per dimension than sparse vectors, capturing complex patterns and relationships for easier analysis in high-dimensional spaces. For example, in a sparse vector, the vectors for <strong>king</strong> and <strong>queen</strong> would be just as dissimilar as the vectors <em><strong>king</strong></em> and <em><strong>apple</strong></em>, even thought <em><strong>king</strong></em> and <em><strong>queen</strong></em> have related meanings.</p><p>Common applications:</p><ul><li><p>Sentiment analysis</p></li><li><p>Information retrieval with semantic meaning</p></li><li><p>Machine translation</p></li></ul><p></p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!dEJ7!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1ecf5aa4-051a-46cf-9f8e-ba01f5639b44_361x359.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!dEJ7!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1ecf5aa4-051a-46cf-9f8e-ba01f5639b44_361x359.png 424w, https://substackcdn.com/image/fetch/$s_!dEJ7!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1ecf5aa4-051a-46cf-9f8e-ba01f5639b44_361x359.png 848w, https://substackcdn.com/image/fetch/$s_!dEJ7!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1ecf5aa4-051a-46cf-9f8e-ba01f5639b44_361x359.png 1272w, https://substackcdn.com/image/fetch/$s_!dEJ7!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1ecf5aa4-051a-46cf-9f8e-ba01f5639b44_361x359.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!dEJ7!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1ecf5aa4-051a-46cf-9f8e-ba01f5639b44_361x359.png" width="361" height="359" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/1ecf5aa4-051a-46cf-9f8e-ba01f5639b44_361x359.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:359,&quot;width&quot;:361,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:30416,&quot;alt&quot;:&quot;Dense Matrix&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="Dense Matrix" title="Dense Matrix" srcset="https://substackcdn.com/image/fetch/$s_!dEJ7!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1ecf5aa4-051a-46cf-9f8e-ba01f5639b44_361x359.png 424w, https://substackcdn.com/image/fetch/$s_!dEJ7!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1ecf5aa4-051a-46cf-9f8e-ba01f5639b44_361x359.png 848w, https://substackcdn.com/image/fetch/$s_!dEJ7!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1ecf5aa4-051a-46cf-9f8e-ba01f5639b44_361x359.png 1272w, https://substackcdn.com/image/fetch/$s_!dEJ7!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1ecf5aa4-051a-46cf-9f8e-ba01f5639b44_361x359.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image buttonBase-GK1x3M"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image buttonBase-GK1x3M"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">Example of a dense matrix</figcaption></figure></div><p></p><p></p><h2>Hybrid Search</h2><p>Hybrid search leverages the strengths of both approaches, combining the precision of <strong>sparse vectors</strong> with the deep contextual comprehension of <strong>dense vectors</strong>. This combination ensures that no important documents are overlooked, whether they align precisely with the query or capture its broader intent.</p><p>In the following section I am going to demonstrate how using hybrid search in a RAG pipeline can improve the results of the retrieval phase.</p><p></p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!vK_a!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F05acb404-bbcc-438c-a723-e201bb5af6a9_1897x1062.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!vK_a!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F05acb404-bbcc-438c-a723-e201bb5af6a9_1897x1062.png 424w, https://substackcdn.com/image/fetch/$s_!vK_a!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F05acb404-bbcc-438c-a723-e201bb5af6a9_1897x1062.png 848w, https://substackcdn.com/image/fetch/$s_!vK_a!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F05acb404-bbcc-438c-a723-e201bb5af6a9_1897x1062.png 1272w, https://substackcdn.com/image/fetch/$s_!vK_a!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F05acb404-bbcc-438c-a723-e201bb5af6a9_1897x1062.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!vK_a!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F05acb404-bbcc-438c-a723-e201bb5af6a9_1897x1062.png" width="1456" height="815" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/05acb404-bbcc-438c-a723-e201bb5af6a9_1897x1062.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:815,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:127712,&quot;alt&quot;:&quot;Hybrid search RAG pipeline&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="Hybrid search RAG pipeline" title="Hybrid search RAG pipeline" srcset="https://substackcdn.com/image/fetch/$s_!vK_a!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F05acb404-bbcc-438c-a723-e201bb5af6a9_1897x1062.png 424w, https://substackcdn.com/image/fetch/$s_!vK_a!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F05acb404-bbcc-438c-a723-e201bb5af6a9_1897x1062.png 848w, https://substackcdn.com/image/fetch/$s_!vK_a!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F05acb404-bbcc-438c-a723-e201bb5af6a9_1897x1062.png 1272w, https://substackcdn.com/image/fetch/$s_!vK_a!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F05acb404-bbcc-438c-a723-e201bb5af6a9_1897x1062.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image buttonBase-GK1x3M"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image buttonBase-GK1x3M"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">Hybrid Search RAG pipeline</figcaption></figure></div><p></p><h2>Practical Implementation</h2><p>To be able to use hybrid search we require a model embeddings with the capability to generate embeddings as dense and sparse vectors. <strong>M3-Embedding</strong>: A new versatile  model for Multi-Linguality, Multi-Functionality, and Multi-Granularity. It provides a uniform support for the semantic retrieval of more than 100 working languages. It can simultaneously accomplish the three common retrieval functionalities: d<strong>ense retrieval</strong>, multi-vector retrieval, and <strong>sparse retrieval.</strong> Besides, it is also capable of processing inputs of different granularities, spanning from short sentences to long documents of up to 8,192 tokens [4].</p><p>For the demonstration I will use the <a href="https://huggingface.co/datasets/rag-datasets/rag-mini-wikipedia/viewer/question-answer/test?q=elephant">rag-mini-wikipedia</a> dataset which has a corpus of <strong>3200</strong> questions in different topics.</p><p>Then I will use <strong><a href="https://github.com/milvus-io">Milvus</a></strong> which is an open-source  vector database that supports both types of vectors (<em>sparse</em> and <em>dense</em>) in one collection, allowing for hybrid search that enhances the result relevance.</p><p>The Jupyter notebook with the implementation and results can be found <strong><a href="https://nbviewer.org/gist/albertollamaso/d18772753b66dadf1a9216bf50e6985c">here</a></strong> and in this article I wanted to highlight the steps performed on the notebook and an analysis of the results. For the whole implementation refer to the Jupyter notebook and the references at the end of the article.</p><p></p><h4>Analysis of the dataset</h4><p>After downloading the dataset we can explore the content. We can see that it is type <em>Dataset</em> with two features <em><strong>passage</strong></em> and <em><strong>id</strong></em> and it contains <strong>3200</strong> rows. </p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!wYyb!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4d01a06b-666d-4cc7-845b-19d81d78d79b_334x152.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!wYyb!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4d01a06b-666d-4cc7-845b-19d81d78d79b_334x152.png 424w, https://substackcdn.com/image/fetch/$s_!wYyb!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4d01a06b-666d-4cc7-845b-19d81d78d79b_334x152.png 848w, https://substackcdn.com/image/fetch/$s_!wYyb!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4d01a06b-666d-4cc7-845b-19d81d78d79b_334x152.png 1272w, https://substackcdn.com/image/fetch/$s_!wYyb!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4d01a06b-666d-4cc7-845b-19d81d78d79b_334x152.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!wYyb!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4d01a06b-666d-4cc7-845b-19d81d78d79b_334x152.png" width="334" height="152" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/4d01a06b-666d-4cc7-845b-19d81d78d79b_334x152.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:152,&quot;width&quot;:334,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:13199,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!wYyb!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4d01a06b-666d-4cc7-845b-19d81d78d79b_334x152.png 424w, https://substackcdn.com/image/fetch/$s_!wYyb!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4d01a06b-666d-4cc7-845b-19d81d78d79b_334x152.png 848w, https://substackcdn.com/image/fetch/$s_!wYyb!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4d01a06b-666d-4cc7-845b-19d81d78d79b_334x152.png 1272w, https://substackcdn.com/image/fetch/$s_!wYyb!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4d01a06b-666d-4cc7-845b-19d81d78d79b_334x152.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p></p><p>The query I will explore on the demonstration is the following: <strong>Where Elephants live?</strong></p><p></p><h4>Results</h4><p>After creating the embeddings of the corpus as dense and sparse vectors and inserting them into the Milvus collection I performed 3 types or search: <strong>Dense search</strong>, <strong>Sparse search</strong> and <strong>Hybrid search</strong> and limiting the results to the top 3. Let&#8217;s see the results of each of them.</p><p></p><h5>Dense Search Results</h5><p></p><p><code>distance: 0.6662917137145996 </code></p><p><code>text: Elephants (Elephantidae) are a family in the order Proboscidea in the class Mammalia. They were once classified along with other thick skinned animals in a now invalid order, Pachydermata. There are three living species: the African Bush Elephant, the African Forest Elephant (until recently known collectively as the African Elephant), and the Asian Elephant (also known as the Indian Elephant). Other species have become extinct since the last ice age, which ended about 10,000 years ago, the Mammoth being the most well-known of these. </code></p><p><code>distance: 0.6637986898422241 </code></p><p><code>text: Elephants are also commonly exhibited in zoos and wild animal parks.</code></p><p></p><p><code>distance: 0.6518104076385498 </code></p><p><code>text: Elephant footprints (tire tracks for scale)Elephants live in a structured social order. The social lives of male and female elephants are very different. The females spend their entire lives in tightly knit family groups made up of mothers, daughters, sisters, and aunts. These groups are led by the eldest female, or matriarch. Adult males, on the other hand, live mostly solitary lives.</code></p><p></p><p>Not bad results at all. The documents retrieved using dense search captured the context and semantic of the question and matched with the best documents.</p><p></p><h5>Sparse Search Results</h5><p></p><p><code>distance: 0.22559085488319397 </code></p><p><code>text: Elephants are mammals, and the largest land animals alive today. The elephant's gestation period is 22 months, the longest of any land animal. At birth it is common for an elephant calf to weigh 120 kilograms (265 lb). An elephant may live as long as 70 years, sometimes longer. The largest elephant ever recorded was shot in Angola in 1956. This male weighed about 12,000 kg (26,400 lb), with a shoulder height of 4.2 m (13.8 ft), a metre (3 ft 4 in) taller than the average male African elephant. The smallest elephants, about the size of a calf or a large pig, were a prehistoric species that lived on the island of Crete during the Pleistocene epoch. Bate, D.M.A. 1907. On Elephant Remains from Crete, with Description of Elephas creticus sp.n. Proc. zool. Soc. London: 238-250. </code></p><p><code>distance: 0.20308682322502136 </code></p><p><code>text: Elephants (Elephantidae) are a family in the order Proboscidea in the class Mammalia. They were once classified along with other thick skinned animals in a now invalid order, Pachydermata. There are three living species: the African Bush Elephant, the African Forest Elephant (until recently known collectively as the African Elephant), and the Asian Elephant (also known as the Indian Elephant). Other species have become extinct since the last ice age, which ended about 10,000 years ago, the Mammoth being the most well-known of these.</code></p><p></p><p><code>distance: 0.18690812587738037 </code></p><p><code>text: Elephant footprints (tire tracks for scale)Elephants live in a structured social order. The social lives of male and female elephants are very different. The females spend their entire lives in tightly knit family groups made up of mothers, daughters, sisters, and aunts. These groups are led by the eldest female, or matriarch. Adult males, on the other hand, live mostly solitary lives.</code></p><p></p><p>We can noticed more poor results using sparse vectors which is expected. If we really want to capture the semantic of the query and document we cannot rely on sparse vectors.</p><p></p><h5>Hybrid Search Results</h5><p><code>distance: 1.2508615255355835 </code></p><p><code>text: Elephants (Elephantidae) are a family in the order Proboscidea in the class Mammalia. They were once classified along with other thick skinned animals in a now invalid order, Pachydermata. There are three living species: the African Bush Elephant, the African Forest Elephant (until recently known collectively as the African Elephant), and the Asian Elephant (also known as the Indian Elephant). Other species have become extinct since the last ice age, which ended about 10,000 years ago, the Mammoth being the most well-known of these.</code></p><p></p><p><code>distance: 1.2426867485046387 text: Elephant footprints (tire tracks for scale)Elephants live in a structured social order. The social lives of male and female elephants are very different. The females spend their entire lives in tightly knit family groups made up of mothers, daughters, sisters, and aunts. These groups are led by the eldest female, or matriarch. Adult males, on the other hand, live mostly solitary lives. </code></p><p></p><p><code>distance: 0.6865341663360596 </code></p><p><code>text: Elephants are also commonly exhibited in zoos and wild animal parks.</code></p><p></p><p>Very similar results to the dense search but enhanced in the documents retrieved. We can see on this query and any other that you can imagine how hybrid search can improve the results quality during the retrieval phase of a RAG pipeline.</p><p></p><h2>Conclusions</h2><p>We can constatate that using dense and hybrid search we obtained the best results. For different queries we can obtain different results while having a hybrid search we can enhanced the results during the retrieval phase.</p><p>The are different parameters and mechanism we could tweak on this pipeline like the rerank weights for each type of vectors depending in our needs.</p><p> Another advanced techniques to explore to enhanced the performance of the RAG pipeline that I do not explore in this article are:</p><ul><li><p><strong>Creating sub-queries:</strong> When a user query is too complicated, we can use an LLM to break it down into simpler sub-queries before passing them on to the vector database and the LLM. Let&#8217;s take a look at an example.</p></li><li><p><strong>Filtered search:</strong> An ANN search identifies vector embeddings similar to a given query but may not always yield accurate results. Adding filtering conditions narrows the search scope to entities matching specific criteria, improving precision.</p></li></ul><p>If you want to see how I am using filtered search to build an AI tool that helps SREs and DevOps teams to gain visibility into their systems and applications check <a href="https://github.com/Trint-ai/sre-buddy">here</a>.</p><p>In future posts I would like to explore more advanced RAG techniques and performing observability on RAG using for instance <a href="https://www.langchain.com/langsmith">LangSmith</a> and other available tools.</p><p></p><h3>References</h3><p>[1] <a href="https://arxiv.org/abs/2410.12837">A Comprehensive Survey of Retrieval-Augmented Generation (RAG): Evolution, Current Landscape and Future Directions</a></p><p>[2] <a href="https://github.com/milvus-io">The Milvus Project</a></p><p>[3] <a href="https://huggingface.co/datasets/rag-datasets/rag-mini-wikipedia">Dataset: rag-mini-wikipedia</a></p><p>[4] <a href="https://arxiv.org/pdf/2402.03216">M3-Embedding: Multi-Linguality, Multi-Functionality, Multi-Granularity Text Embeddings Through Self-Knowledge Distillation</a></p><p>[5] <a href="https://nbviewer.org/gist/albertollamaso/d18772753b66dadf1a9216bf50e6985c">Jupyter Notebook: Hybrid Search RAG with Milvus</a></p><p>[6] <a href="https://github.com/Trint-ai/sre-buddy">AI tool that helps SREs and DevOps teams to gain visibility into their systems and applications</a></p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://blog.x504.dev/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Thanks for reading Deep Life Learning! Subscribe for free to receive new posts and support my work.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div>]]></content:encoded></item><item><title><![CDATA[Sudoku Meets Constraint Programming]]></title><description><![CDATA[A Smart Solution Guide]]></description><link>https://blog.x504.dev/p/sudoku-meets-constraint-programming</link><guid isPermaLink="false">https://blog.x504.dev/p/sudoku-meets-constraint-programming</guid><dc:creator><![CDATA[x504]]></dc:creator><pubDate>Sun, 01 Dec 2024 09:42:02 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!ws-V!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4682414e-3dd3-4eca-902c-3025868cdcbc_676x558.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Constraint programming is a powerful approach for modeling and solving complex combinatorial problems. It works by representing problems through variables and the constraints imposed on them, enabling a systematic exploration of the solution space to identify feasible or optimal solutions. Many decision problems are so hard that there is no rule for any a-priori &#8220;better&#8220; approach. </p><p></p><blockquote><p>Constraint programming is a powerful paradigm for solving combinatorial search problems that draws on a wide range of techniques from artificial intelligence, computer science, and operations research. Constraint programming is &#8220;programming&#8221; partly in the sense of programming in mathematical programming.</p></blockquote><p></p><p>The <a href="https://developers.google.com/optimization">Google OR-Tools</a> are an open source software suite for optimization, tuned for tackling the world's toughest problems in vehicle routing, flows, integer and linear programming, and constraint programming.</p><p>In this article, I will demonstrate how to leverage constraint programming and Google's OR-Tools to solve a <a href="https://en.wikipedia.org/wiki/Sudoku">Sudoku</a> puzzle efficiently.</p><p></p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://blog.x504.dev/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Thanks for reading Deep Life Learning! Subscribe for free to receive new posts and support my work.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><p></p><p></p><h3>Solving the Game</h3><p></p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!ws-V!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4682414e-3dd3-4eca-902c-3025868cdcbc_676x558.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!ws-V!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4682414e-3dd3-4eca-902c-3025868cdcbc_676x558.png 424w, https://substackcdn.com/image/fetch/$s_!ws-V!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4682414e-3dd3-4eca-902c-3025868cdcbc_676x558.png 848w, https://substackcdn.com/image/fetch/$s_!ws-V!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4682414e-3dd3-4eca-902c-3025868cdcbc_676x558.png 1272w, https://substackcdn.com/image/fetch/$s_!ws-V!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4682414e-3dd3-4eca-902c-3025868cdcbc_676x558.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!ws-V!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4682414e-3dd3-4eca-902c-3025868cdcbc_676x558.png" width="460" height="379.70414201183434" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/4682414e-3dd3-4eca-902c-3025868cdcbc_676x558.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:558,&quot;width&quot;:676,&quot;resizeWidth&quot;:460,&quot;bytes&quot;:43169,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!ws-V!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4682414e-3dd3-4eca-902c-3025868cdcbc_676x558.png 424w, https://substackcdn.com/image/fetch/$s_!ws-V!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4682414e-3dd3-4eca-902c-3025868cdcbc_676x558.png 848w, https://substackcdn.com/image/fetch/$s_!ws-V!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4682414e-3dd3-4eca-902c-3025868cdcbc_676x558.png 1272w, https://substackcdn.com/image/fetch/$s_!ws-V!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4682414e-3dd3-4eca-902c-3025868cdcbc_676x558.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image buttonBase-GK1x3M"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image buttonBase-GK1x3M"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption"><strong>Figure 1 - The Sudoku puzzle to solve</strong></figcaption></figure></div><p><strong>The objective of Sudoku is to complete the grid by filling in the digits 1 through 9, ensuring that each digit appears exactly once in every row, every column, and each 3x3 sub-grid.</strong></p><p>In the <strong>Figure 1</strong>, we can see the Sudoku puzzle we will solve. However, as previously explained, by defining a constraint programming model, we can solve any Sudoku puzzle without altering the program's logic. The only modification required is to update the input variables that define the game's initial state.</p><p>In constraint programming, models are built using variables and constraints. Let&#8217;s define the decision variables.</p><p></p><h4>Decision Variables</h4><p>We begin by defining integer variables to represent each square in the Sudoku puzzle. These variables are constrained to take on values between 1 and 9.</p><pre><code># p(i,j,n): is true&#9;when the number 'n' is in the cell in the 'ith' row&#9;and&#9;the&#9;'jth' column.

propositions = {}
for i in rows:
    for j in columns:
        propositions[(i, j)] = model.NewIntVar(1, 9, f'i{i}_j{j}')</code></pre><h4>Constraints</h4><p>With all the decision variables of our model defined, the next step is to apply the explicit constraints of the Sudoku puzzle. This involves assigning the predefined numbers from the puzzle's initial setup to their corresponding variables.</p><h5>Set the initial status of the game</h5><pre><code># Define explicit constraints (the start status of the given game)
model.Add(propositions[(2, 1)] == 7)
model.Add(propositions[(6, 1)] == 3)
model.Add(propositions[(7, 1)] == 5)
model.Add(propositions[(9, 1)] == 6)

model.Add(propositions[(3, 2)] == 9)
model.Add(propositions[(5, 2)] == 5)
model.Add(propositions[(7, 2)] == 7)

model.Add(propositions[(2, 3)] == 5)
model.Add(propositions[(5, 3)] == 9)

model.Add(propositions[(5, 4)] == 6)
model.Add(propositions[(8, 4)] == 3)
model.Add(propositions[(9, 4)] == 4)

model.Add(propositions[(2, 5)] == 2)
model.Add(propositions[(6, 5)] == 1)
model.Add(propositions[(7, 5)] == 6)

model.Add(propositions[(4, 6)] == 4)

model.Add(propositions[(3, 7)] == 4)
model.Add(propositions[(7, 7)] == 1)

model.Add(propositions[(1, 8)] == 3)
model.Add(propositions[(6, 8)] == 5)

model.Add(propositions[(4, 9)] == 2)
model.Add(propositions[(5, 9)] == 8)
model.Add(propositions[(9, 9)] == 5)</code></pre><p>Next, we will define the implicit constraints that stem directly from the core rules of Sudoku.</p><h5>No digit can occur twice in any of the rows</h5><pre><code>for i in rows:
  model.AddAllDifferent([propositions[(i, j)] for j in columns])</code></pre><h5>No digit can occur twice in any of the columns</h5><pre><code>for j in rows:
    model.AddAllDifferent([propositions[(i, j)] for i in columns])</code></pre><h5>No digit can occur twice any of the 3x3 sub-grids</h5><pre><code>for i in range(n):
    for j in range(n):
        model.AddAllDifferent([propositions[(ii, jj)] for ii in range(1 + i * n, 1 + (i + 1) * n) for jj in
                                range(1 + j * n, 1 + (j + 1) * n)])</code></pre><p></p><h4>Solve the game</h4><p>Constraint programming solves problems by combining systematic search with inference techniques. The search explores all possible variable-value combinations, forming a tree where the root represents the original problem.</p><p>Here the <em>CPSolver</em> from Google OR-Tools is invoked with the given task to solve the problem and provide the solution of our Sudoku puzzle.</p><pre><code>solver = cp_model.CpSolver()
solver.SearchForAllSolutions(model, SolutionPrinter(propositions))</code></pre><p></p><h4>Solutions</h4><p>Finally, with the help of the <em>SolutionPrinter</em> python class we can print the all solutions found by the solver.</p><pre><code>solution 1
[2, 6, 1, 8, 4, 7, 5, 3, 9]
[7, 4, 5, 9, 2, 3, 6, 8, 1]
[8, 9, 3, 1, 5, 6, 4, 2, 7]
[1, 8, 7, 5, 9, 4, 3, 6, 2]
[4, 5, 9, 6, 3, 2, 7, 1, 8]
[3, 2, 6, 7, 1, 8, 9, 5, 4]
[5, 7, 8, 2, 6, 9, 1, 4, 3]
[9, 1, 4, 3, 8, 5, 2, 7, 6]
[6, 3, 2, 4, 7, 1, 8, 9, 5]

solution 2
[2, 6, 8, 7, 4, 9, 5, 3, 1]
[7, 4, 5, 1, 2, 3, 6, 8, 9]
[1, 9, 3, 5, 8, 6, 4, 2, 7]
[8, 1, 7, 9, 5, 4, 3, 6, 2]
[4, 5, 9, 6, 3, 2, 7, 1, 8]
[3, 2, 6, 8, 1, 7, 9, 5, 4]
[5, 7, 4, 2, 6, 8, 1, 9, 3]
[9, 8, 1, 3, 7, 5, 2, 4, 6]
[6, 3, 2, 4, 9, 1, 8, 7, 5]

solution 3
[2, 6, 1, 7, 4, 8, 5, 3, 9]
[7, 4, 5, 9, 2, 3, 6, 8, 1]
[8, 9, 3, 1, 5, 6, 4, 2, 7]
[1, 8, 7, 5, 9, 4, 3, 6, 2]
[4, 5, 9, 6, 3, 2, 7, 1, 8]
[3, 2, 6, 8, 1, 7, 9, 5, 4]
[5, 7, 8, 2, 6, 9, 1, 4, 3]
[9, 1, 4, 3, 8, 5, 2, 7, 6]
[6, 3, 2, 4, 7, 1, 8, 9, 5]

solution 4
[2, 6, 1, 9, 4, 8, 5, 3, 7]
[7, 4, 5, 1, 2, 3, 6, 8, 9]
[8, 9, 3, 7, 5, 6, 4, 2, 1]
[1, 8, 7, 5, 9, 4, 3, 6, 2]
[4, 5, 9, 6, 3, 2, 7, 1, 8]
[3, 2, 6, 8, 1, 7, 9, 5, 4]
[5, 7, 8, 2, 6, 9, 1, 4, 3]
[9, 1, 4, 3, 8, 5, 2, 7, 6]
[6, 3, 2, 4, 7, 1, 8, 9, 5]

solution 5
[2, 8, 6, 7, 4, 9, 5, 3, 1]
[7, 4, 5, 1, 2, 3, 6, 8, 9]
[1, 9, 3, 5, 8, 6, 4, 2, 7]
[8, 1, 7, 9, 5, 4, 3, 6, 2]
[4, 5, 9, 6, 3, 2, 7, 1, 8]
[3, 6, 2, 8, 1, 7, 9, 5, 4]
[5, 7, 4, 2, 6, 8, 1, 9, 3]
[9, 2, 1, 3, 7, 5, 8, 4, 6]
[6, 3, 8, 4, 9, 1, 2, 7, 5]</code></pre><p>The full code is provided below:</p><pre><code>from ortools.sat.python import cp_model

rows = [1, 2, 3, 4, 5, 6, 7, 8, 9]
columns = [1, 2, 3, 4, 5, 6, 7, 8, 9]
n = 3  # size of sub-grids


class SolutionPrinter(cp_model.CpSolverSolutionCallback):
    def __init__(self, propositions):
        cp_model.CpSolverSolutionCallback.__init__(self)
        self.propositions_ = propositions
        self.solutions_ = 0

    def OnSolutionCallback(self):
        self.solutions_ = self.solutions_ + 1
        print("solution", self.solutions_)

        for i in rows:
            row_solution = []
            for j in columns:
                row_solution.append(self.Value(self.propositions_[(i, j)]))
            print(row_solution)

        print()


def main():
    # Create the CP-SAT model.
    model = cp_model.CpModel()

    # Create the decision variables
    # p(i,j,n): is true&#9;when the number 'n' is in the cell in the 'ith'&#9;row&#9;and&#9;the&#9;'jth' column.
    propositions = {}
    for i in rows:
        for j in columns:
            propositions[(i, j)] = model.NewIntVar(1, 9, f'i{i}_j{j}')

    # Define explicit constraints (the start status of the given game)
    model.Add(propositions[(2, 1)] == 7)
    model.Add(propositions[(6, 1)] == 3)
    model.Add(propositions[(7, 1)] == 5)
    model.Add(propositions[(9, 1)] == 6)

    model.Add(propositions[(3, 2)] == 9)
    model.Add(propositions[(5, 2)] == 5)
    model.Add(propositions[(7, 2)] == 7)

    model.Add(propositions[(2, 3)] == 5)
    model.Add(propositions[(5, 3)] == 9)

    model.Add(propositions[(5, 4)] == 6)
    model.Add(propositions[(8, 4)] == 3)
    model.Add(propositions[(9, 4)] == 4)

    model.Add(propositions[(2, 5)] == 2)
    model.Add(propositions[(6, 5)] == 1)
    model.Add(propositions[(7, 5)] == 6)

    model.Add(propositions[(4, 6)] == 4)

    model.Add(propositions[(3, 7)] == 4)
    model.Add(propositions[(7, 7)] == 1)

    model.Add(propositions[(1, 8)] == 3)
    model.Add(propositions[(6, 8)] == 5)

    model.Add(propositions[(4, 9)] == 2)
    model.Add(propositions[(5, 9)] == 8)
    model.Add(propositions[(9, 9)] == 5)

    # B) Constraints: no digit can occur twice in any of the rows or columns
    # or in any of the 3x3 sub-grids

    # no digit can occur twice in any of the rows
    for i in rows:
        model.AddAllDifferent([propositions[(i, j)] for j in columns])

    # no digit can occur twice in any of the columns
    for j in rows:
        model.AddAllDifferent([propositions[(i, j)] for i in columns])

    # no digit can occur twice any of the 3x3 sub-grids
    for i in range(n):
        for j in range(n):
            model.AddAllDifferent([propositions[(ii, jj)] for ii in range(1 + i * n, 1 + (i + 1) * n) for jj in
                                   range(1 + j * n, 1 + (j + 1) * n)])

    # Declare the solver and search for all solutions and print them in the callback Class
    solver = cp_model.CpSolver()
    solver.SearchForAllSolutions(model, SolutionPrinter(propositions))


main()
</code></pre><p>Getting the some statistics on the solution found we can see interesting things as the <strong>walltime</strong>, <strong>usertime</strong>, <strong>deterministic_time</strong>, <strong>branches</strong>, <strong>propagations</strong> and of course the <strong>status</strong>.</p><pre><code>Response stats: CpSolverResponse summary:
status: OPTIMAL
objective: 0
best_bound: 0
integers: 6
booleans: 8
conflicts: 0
branches: 100
propagations: 239
integer_propagations: 419
restarts: 49
lp_iterations: 0
walltime: 0.010958
usertime: 0.010958
deterministic_time: 0.00225428
gap_integral: 0
solution_fingerprint: 0x1ad791e213b2d87f</code></pre><p>More information about these metrics can be found <a href="https://developers.google.com/optimization/reference/python/sat/python/cp_model">here</a>.</p><p></p><blockquote><p>Constraint Programming represents one if the closest approaches computer science has yet made to the Holy Grail of programming: the user states the problem, the computer solves it.</p><p><em>Eugene C. Freuder, Inaugural issue of the Constraints Journal, 1997</em></p></blockquote><p></p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://blog.x504.dev/p/sudoku-meets-constraint-programming?utm_source=substack&utm_medium=email&utm_content=share&action=share&quot;,&quot;text&quot;:&quot;Share&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://blog.x504.dev/p/sudoku-meets-constraint-programming?utm_source=substack&utm_medium=email&utm_content=share&action=share"><span>Share</span></a></p><p></p><h3>References</h3><p>[1] <a href="https://dl.acm.org/doi/10.5555/2843512#">Francesca Rossi, Peter van Beek, and Toby Walsh. 2006. Handbook of Constraint Programming. Elsevier Science Inc., USA.</a></p><p>[2] <a href="https://developers.google.com/optimization">Google OR-Tools</a></p><p></p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://blog.x504.dev/p/sudoku-meets-constraint-programming/comments&quot;,&quot;text&quot;:&quot;Leave a comment&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://blog.x504.dev/p/sudoku-meets-constraint-programming/comments"><span>Leave a comment</span></a></p><p></p>]]></content:encoded></item><item><title><![CDATA[The Hazards of Large Language Models]]></title><description><![CDATA[Last week, a group of former employees from leading AI companies such as OpenAI and Google DeepMind publicly released a letter warning about recent advances in Artificial Intelligence (AI).]]></description><link>https://blog.x504.dev/p/the-hazards-of-large-language-models</link><guid isPermaLink="false">https://blog.x504.dev/p/the-hazards-of-large-language-models</guid><dc:creator><![CDATA[x504]]></dc:creator><pubDate>Sat, 15 Jun 2024 07:36:52 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!5q5e!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe050775e-41ea-4011-b9b6-8250e6306ba8_304x415.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Last week, a group of former employees from leading AI companies such as <a href="https://openai.com/">OpenAI</a> and <a href="https://deepmind.google/">Google DeepMind</a> publicly released a <a href="https://righttowarn.ai/">letter</a> warning about recent advances in Artificial Intelligence (AI). They highlighted internal flaws and detailed how these technologies are being developed, leading to issues such as inequality, manipulation, and misinformation.</p><p>The letter can be found <a href="https://righttowarn.ai/">here</a>, but it is crucial to delve deeper into their warnings and understand how these generative AI applications can harm society and potentially lead to catastrophic consequences. Understanding these risks is vital for addressing the ethical and societal implications of AI development. Specifically in Large Language Models.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!5q5e!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe050775e-41ea-4011-b9b6-8250e6306ba8_304x415.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!5q5e!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe050775e-41ea-4011-b9b6-8250e6306ba8_304x415.png 424w, https://substackcdn.com/image/fetch/$s_!5q5e!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe050775e-41ea-4011-b9b6-8250e6306ba8_304x415.png 848w, https://substackcdn.com/image/fetch/$s_!5q5e!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe050775e-41ea-4011-b9b6-8250e6306ba8_304x415.png 1272w, https://substackcdn.com/image/fetch/$s_!5q5e!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe050775e-41ea-4011-b9b6-8250e6306ba8_304x415.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!5q5e!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe050775e-41ea-4011-b9b6-8250e6306ba8_304x415.png" width="304" height="415" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/e050775e-41ea-4011-b9b6-8250e6306ba8_304x415.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:415,&quot;width&quot;:304,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:306498,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!5q5e!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe050775e-41ea-4011-b9b6-8250e6306ba8_304x415.png 424w, https://substackcdn.com/image/fetch/$s_!5q5e!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe050775e-41ea-4011-b9b6-8250e6306ba8_304x415.png 848w, https://substackcdn.com/image/fetch/$s_!5q5e!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe050775e-41ea-4011-b9b6-8250e6306ba8_304x415.png 1272w, https://substackcdn.com/image/fetch/$s_!5q5e!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe050775e-41ea-4011-b9b6-8250e6306ba8_304x415.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image buttonBase-GK1x3M"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image buttonBase-GK1x3M"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p></p><h2>Environmental Risks and Equality</h2><p>Recent advancements in hardware and techniques for training neural networks have led to the development of a new generation of large models trained on vast datasets. These models have achieved significant improvements in accuracy across numerous natural language processing (NLP) tasks. However, these gains are heavily dependent on the availability of extensive computational resources, which require substantial energy consumption.</p><p>As a result these models are costly to train and develop, both financially, due to the cost of hardware and electricity or cloud compute time, and environmentally, due to the carbon footprint required to fuel modern tensor processing hardware.</p><p>Recent benchmarks have quantified the costs of model training and development in both dollars and estimated CO2 emissions. While the average person is responsible for approximately 5 tons of CO2 annually, the authors found that training a large Transformer model using neural architecture search emitted an estimated 284 tons of CO2. Furthermore, training a single <a href="https://arxiv.org/abs/1810.04805">BERT</a> base model (without hyperparameter tuning) on GPUs was estimated to consume as much energy as a trans-American flight.</p><p>The community calls on researchers and companies to report training time and computational resources required when proposing models intended for re-training on downstream tasks, such as new domain adaptation or task-specific fine-tuning. This transparency will facilitate comparisons across models, enabling subsequent users to accurately determine whether the required computational resources are feasible for their specific settings.</p><h4>Equal Access to Computational Resources</h4><p>Recent advances in computing come at a high price, making them inaccessible to many who seek access.</p><p>Restricting this type of research to industry labs disadvantages the NLP research community in several ways. Researchers with innovative ideas but without access to large-scale computing resources are unable to pursue their concepts. This restriction limits certain types of research based on financial resources, further entrenching the <em>"rich get richer"</em> cycle in research funding. </p><p>Successful and well-funded groups continue to attract more funding due to their existing achievements. Additionally, the high start-up costs of building in-house resources compel less resource-rich groups to depend on cloud computing services like AWS, Google Cloud, and Microsoft Azure.</p><h4>Prioritize Hardware and Algorithms that are Computationally Efficient.</h4><p>It is recommended a collaborative effort between industry and academia to promote the development of more computationally efficient algorithms and energy-efficient hardware. Additionally, efforts should be made to optimize software for better resource efficiency.</p><h2>Biases in Large Internet Datasets</h2><p>The Internet, with its vastness and diversity, might suggest that large datasets like Common Crawl (which includes petabytes of data collected over 8 years of web crawling, a filtered version of which is used in GPT-3 training) are broadly representative of diverse viewpoints. However, closer examination reveals factors that limit participation, discussion inclusion based on crawling methods, and filtered content. Consequently, voices aligned with dominant perspectives, including white supremacist and misogynistic views prevalent in US and UK English, are disproportionately represented. This overrepresentation not only exceeds their prevalence in the general population but also exacerbates biases and harms when these datasets are used to train models.</p><p>The contributors to Internet text collections are disproportionately younger and predominantly from developed countries due to uneven global Internet access. Specific subsets, such as GPT-2's data sourced from Reddit outbound links, reflect demographics where a majority are young men in the United States. Similarly, surveys of Wikipedia contributors indicate a low representation of women, highlighting skewed participation demographics in these datasets.</p><p>Social movements introduce new norms, languages, and modes of communication. This poses challenges for language models (LMs), as reliance on these models risks perpetuating outdated and less inclusive viewpoints&#8212;a phenomenon known as '<em>value-lock</em>'.</p><p>For example, the Black Lives Matter (BLM) movement has influenced the creation and editing of Wikipedia articles. As the movement gained momentum, articles on shootings of Black individuals increased in frequency and were generated more quickly. Notably, past incidents of police brutality and shootings were updated alongside new events, demonstrating how social movements connect events over time to construct coherent narratives.</p><p>Recent studies confirm that large language models (LMs) exhibit biases such as stereotypical associations and negative sentiment toward specific groups. Additionally, there is evidence of intersectional bias, where models like BERT, ELMo, GPT, and GPT-2 encode more bias against identities marginalized along multiple dimensions than expected. These biases are attributed to characteristics of the training data. For example, recent research reveals that BERT associates phrases about disabilities with negative sentiments, and topics like gun violence and homelessness are disproportionately linked to discussions of mental illness. Similarly,  GPT-3, trained on extensive data primarily from Common Crawl, can generate highly toxic sentences even when prompted with non-toxic inputs. Their analysis of GPT-2's training data also uncovered significant content from unreliable news sites and banned subreddits.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://blog.x504.dev/p/the-hazards-of-large-language-models?utm_source=substack&utm_medium=email&utm_content=share&action=share&quot;,&quot;text&quot;:&quot;Share&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://blog.x504.dev/p/the-hazards-of-large-language-models?utm_source=substack&utm_medium=email&utm_content=share&action=share"><span>Share</span></a></p><h2>Synthetic Text as Meaningful Source</h2><p>Traditional n-gram language models are limited to modeling local dependencies, predicting each word based on a small sequence of preceding words. In contrast, Transformer-based language models like GPT-3 and GPT-4 can capture much larger contexts, generating text that is not only fluent but also coherent across paragraphs.</p><p>For instance, to demonstrate the GPT-4&#8217;s capability by prompting it with a specific text excerpt, after which it autonomously generated coherent paragraphs, including answers in a Q&amp;A format:</p><blockquote><p><strong>Question</strong>: What is the name of the Russian mercenary group?</p><p><strong>Answer:</strong> The Russian mercenary group often referred to in the media is known as the Wagner Group. This private military company (PMC) has gained attention for its involvement in various conflicts, including in Syria and Ukraine, where it has operated in support of Russian interests. The Wagner Group is known for its operations alongside Russian military forces and has been linked to controversial activities and alleged human rights abuses.</p></blockquote><p></p><blockquote><p><strong>Question</strong>: Where is the Wagner group?</p><p><strong>Answer</strong>: The Wagner Group, a Russian private military company (PMC), has been known to operate in several conflict zones and areas of interest to Russia. Some of the places where Wagner Group operatives have been reported include: Syria, Ukraine, Libya, Central African Republic (CAR) and Sudan.</p></blockquote><p></p><blockquote><p><strong>Question:</strong> Who is the leader of the Wagner group?</p><p><strong>Answer:</strong> The leader of the Wagner Group, the Russian private military company (PMC), is believed to be Dmitry Utkin. Dmitry Utkin is a former Russian military officer who reportedly founded the Wagner Group and has been linked to its operations in various conflict zones. Utkin, also known by his call sign "Wagner," is said to have a background in military intelligence and has been associated with coordinating and commanding Wagner Group operations. However, due to the secretive nature of private military companies like Wagner, detailed information about its leadership and structure can be difficult to verify.</p></blockquote><p></p><p>This example showcases GPT-4's ability to maintain coherence and relevance to the initial prompt, exemplifying its broader contextual understanding compared to traditional models.</p><p>Text produced by a Large Language Model lacks grounding in communicative intent, any model of the world, or any model of the reader's state of mind. This is inherent because the training data never involved sharing thoughts with a listener, nor does the machine possess the capability to engage in such interaction. Despite the increasingly fluent nature of automatically generated text, our perception of natural language remains influenced by our own linguistic competence and inclination to interpret communicative acts as conveying coherent meaning and intent, whether or not they actually do. The crux of the issue lies in the fact that if one side of the communication lacks genuine meaning, any comprehension of implicit meaning is illusory and stems from our unique human comprehension of language, which exists independently of the model.</p><p>I hope this article provides you with a comprehensive understanding of the risks and issues associated with Large Language Models. It's crucial for consumers of these models to be aware of these considerations. Artificial Intelligence, including LLMs, should not remain an abstract and complex field for the general public. It's essential to explain in straightforward terms the challenges researchers currently face and the societal hurdles ahead of us.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://blog.x504.dev/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://blog.x504.dev/subscribe?"><span>Subscribe now</span></a></p><p></p>]]></content:encoded></item><item><title><![CDATA[Autoencoders]]></title><description><![CDATA[Implementation of a denoised Autoencoder]]></description><link>https://blog.x504.dev/p/autoencoders</link><guid isPermaLink="false">https://blog.x504.dev/p/autoencoders</guid><dc:creator><![CDATA[x504]]></dc:creator><pubDate>Thu, 02 May 2024 10:46:19 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!RdKE!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F01725a23-6862-4a07-bc8b-10eb10f1a072_498x410.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>An AutoEncoder (AE) is a neural network design comprising two interconnected networks: Encoder and Decoder. The Encoder takes in the input an image and transforms it into a lower-dimensional latent spatial vector. Subsequently, the Decoder reconstructs this vector to generate an output closely resembling the initial input. Throughout this process, the network is trained. The purpose of Autoencoders is to learn low-dimensional feature representations of the input data.</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!95lx!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febe4d79b-ec8b-4e56-8d97-56bd0f2a166b_550x226.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!95lx!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febe4d79b-ec8b-4e56-8d97-56bd0f2a166b_550x226.png 424w, https://substackcdn.com/image/fetch/$s_!95lx!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febe4d79b-ec8b-4e56-8d97-56bd0f2a166b_550x226.png 848w, https://substackcdn.com/image/fetch/$s_!95lx!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febe4d79b-ec8b-4e56-8d97-56bd0f2a166b_550x226.png 1272w, https://substackcdn.com/image/fetch/$s_!95lx!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febe4d79b-ec8b-4e56-8d97-56bd0f2a166b_550x226.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!95lx!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febe4d79b-ec8b-4e56-8d97-56bd0f2a166b_550x226.png" width="550" height="226" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/ebe4d79b-ec8b-4e56-8d97-56bd0f2a166b_550x226.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:226,&quot;width&quot;:550,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:152209,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!95lx!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febe4d79b-ec8b-4e56-8d97-56bd0f2a166b_550x226.png 424w, https://substackcdn.com/image/fetch/$s_!95lx!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febe4d79b-ec8b-4e56-8d97-56bd0f2a166b_550x226.png 848w, https://substackcdn.com/image/fetch/$s_!95lx!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febe4d79b-ec8b-4e56-8d97-56bd0f2a166b_550x226.png 1272w, https://substackcdn.com/image/fetch/$s_!95lx!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febe4d79b-ec8b-4e56-8d97-56bd0f2a166b_550x226.png 1456w" sizes="100vw" fetchpriority="high"></picture><div></div></div></a></figure></div><p></p><p>Denoising autoencoders exhibit versatility across various domains or application areas, often requiring slight adjustments based on the nature of the dataset being utilized. In this tutorial, we will explore one such variant known as convolutional denoising autoencoders, specifically designed for denoising image data.</p><p>These models take a noisy image as input and employ multiple convolutional operations to extract crucial features. These latent features are then fed into a series of deconvolutional layers to reconstruct a cleaner version of the image, maintaining the same height and width.</p><p></p><h3>Implementation of an Autoencoder</h3><p>The implementation of a basic AE consisted on a network architecture densely connected layers as follow:</p><ul><li><p>Layer 1: 128 Neurons with ReLU activations</p></li><li><p>Layer 2: 64 Neurons with ReLU activations</p></li><li><p>Layer 3: 32 Neurons with ReLU activations</p></li><li><p>Layer 4: 64 Neurons with ReLU activations</p></li><li><p>Layer 5: 128 Neurons with ReLU activations</p></li><li><p>Layer 6: 784 Neurons with Sigmoid activation</p></li></ul><p></p><p>On this AE, I&#8217;ve use the Rectified Linear Unit (ReLU) activation functions for the input and hidden layers and a Sigmoid function as the output layer of the Artificial Neural Network (ANN).</p><p>The ReLU function returns 0 if it receives any negative input, but for any positive value x, it returns the value back. In practice it is fast to compute, hence it has become the most used activation function on ANNs.</p><p>The sigmoid function is a special form of the logistic function. This function is used as an output layer when you want to guarantee that the predictions will always fall within a given range of values, 0 to 1.</p><p></p><h4>Weights Initializer</h4><p>During the process of constructing the AE, the TensorFlow initializer <em><a href="https://www.tensorflow.org/api_docs/python/tf/keras/initializers/RandomNormal">RandomNormal</a></em> was used on the initial experiments. But it was noticed that after the first epoch, the output matrix of the sigmoid layer was containing NaN values. This occurs due a saturation of the sigmoid function. A typical solution for this is problem is use another initialiser that solves this problem or implement a sigmoid function that is numerical stable. On my case I resulting using the<em> <a href="https://www.tensorflow.org/api_docs/python/tf/keras/initializers/HeNormal">HeNormal</a> </em>initialiser provided by TensorFlow.</p><p></p><h4>Optimizer</h4><p>The Adaptive moment estimation (<a href="https://keras.io/api/optimizers/adam/">Adam</a>), is an  adaptive learning rate algorithm for first-order gradient-based optimisation. It is computationally efficient and has a little memory footprint.</p><p>This was the optimizer utilized to update the weights for the AE during training phase. It requires less tuning of the learning rate hyperparameter. The default learning rate <strong>&#951;=0.001 </strong>has been used.</p><p>Here is an illustrative diagram presenting the key components involved on the training phase of an Artificial Neural Network.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!RdKE!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F01725a23-6862-4a07-bc8b-10eb10f1a072_498x410.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!RdKE!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F01725a23-6862-4a07-bc8b-10eb10f1a072_498x410.png 424w, https://substackcdn.com/image/fetch/$s_!RdKE!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F01725a23-6862-4a07-bc8b-10eb10f1a072_498x410.png 848w, https://substackcdn.com/image/fetch/$s_!RdKE!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F01725a23-6862-4a07-bc8b-10eb10f1a072_498x410.png 1272w, https://substackcdn.com/image/fetch/$s_!RdKE!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F01725a23-6862-4a07-bc8b-10eb10f1a072_498x410.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!RdKE!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F01725a23-6862-4a07-bc8b-10eb10f1a072_498x410.png" width="498" height="410" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/01725a23-6862-4a07-bc8b-10eb10f1a072_498x410.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:410,&quot;width&quot;:498,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:64764,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!RdKE!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F01725a23-6862-4a07-bc8b-10eb10f1a072_498x410.png 424w, https://substackcdn.com/image/fetch/$s_!RdKE!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F01725a23-6862-4a07-bc8b-10eb10f1a072_498x410.png 848w, https://substackcdn.com/image/fetch/$s_!RdKE!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F01725a23-6862-4a07-bc8b-10eb10f1a072_498x410.png 1272w, https://substackcdn.com/image/fetch/$s_!RdKE!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F01725a23-6862-4a07-bc8b-10eb10f1a072_498x410.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image buttonBase-GK1x3M"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image buttonBase-GK1x3M"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p></p><h3>Results</h3><p>The code that implement this AutoEncoder using the popular <a href="https://en.wikipedia.org/wiki/MNIST_database">MNIST</a> dataset can be found <a href="https://github.com/albertollamaso/ml_notebooks/blob/main/denoised_autoencoder.ipynb">here</a>. On this case we wanted to show how to implement a <a href="https://keras.io/api/models/model/">Class using Keras</a>.</p><p>The main goal of the training gradient-based phase is to reduce the loss. The loss values across <strong>200 epochs</strong> is shown in the following image.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!6iCt!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0688426b-5dda-4bde-b281-45ff499f1194_584x455.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!6iCt!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0688426b-5dda-4bde-b281-45ff499f1194_584x455.png 424w, https://substackcdn.com/image/fetch/$s_!6iCt!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0688426b-5dda-4bde-b281-45ff499f1194_584x455.png 848w, https://substackcdn.com/image/fetch/$s_!6iCt!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0688426b-5dda-4bde-b281-45ff499f1194_584x455.png 1272w, https://substackcdn.com/image/fetch/$s_!6iCt!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0688426b-5dda-4bde-b281-45ff499f1194_584x455.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!6iCt!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0688426b-5dda-4bde-b281-45ff499f1194_584x455.png" width="584" height="455" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/0688426b-5dda-4bde-b281-45ff499f1194_584x455.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:455,&quot;width&quot;:584,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:33116,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!6iCt!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0688426b-5dda-4bde-b281-45ff499f1194_584x455.png 424w, https://substackcdn.com/image/fetch/$s_!6iCt!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0688426b-5dda-4bde-b281-45ff499f1194_584x455.png 848w, https://substackcdn.com/image/fetch/$s_!6iCt!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0688426b-5dda-4bde-b281-45ff499f1194_584x455.png 1272w, https://substackcdn.com/image/fetch/$s_!6iCt!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0688426b-5dda-4bde-b281-45ff499f1194_584x455.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image buttonBase-GK1x3M"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image buttonBase-GK1x3M"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p></p><p>It is noticed how the model was making improvements on each iteration. It was noticed that after around epoch 70-80 the model was not making any more significant improvement. The final loss obtained after 200 epochs was <strong>0.0479</strong>.</p><p>In order to evaluate the performance of the model in a visual manner. A group of 3 randoms data points (images) were selected from the test dataset and a visualisation of the original, noisy and reconstructed image were generated.</p><p></p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!HLDl!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5c50bdd9-f1a4-449d-bb00-493e4a7554ca_543x211.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!HLDl!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5c50bdd9-f1a4-449d-bb00-493e4a7554ca_543x211.png 424w, https://substackcdn.com/image/fetch/$s_!HLDl!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5c50bdd9-f1a4-449d-bb00-493e4a7554ca_543x211.png 848w, https://substackcdn.com/image/fetch/$s_!HLDl!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5c50bdd9-f1a4-449d-bb00-493e4a7554ca_543x211.png 1272w, https://substackcdn.com/image/fetch/$s_!HLDl!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5c50bdd9-f1a4-449d-bb00-493e4a7554ca_543x211.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!HLDl!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5c50bdd9-f1a4-449d-bb00-493e4a7554ca_543x211.png" width="543" height="211" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/5c50bdd9-f1a4-449d-bb00-493e4a7554ca_543x211.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:211,&quot;width&quot;:543,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:14894,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!HLDl!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5c50bdd9-f1a4-449d-bb00-493e4a7554ca_543x211.png 424w, https://substackcdn.com/image/fetch/$s_!HLDl!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5c50bdd9-f1a4-449d-bb00-493e4a7554ca_543x211.png 848w, https://substackcdn.com/image/fetch/$s_!HLDl!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5c50bdd9-f1a4-449d-bb00-493e4a7554ca_543x211.png 1272w, https://substackcdn.com/image/fetch/$s_!HLDl!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5c50bdd9-f1a4-449d-bb00-493e4a7554ca_543x211.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!dBli!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc6288610-315d-4d09-a1c5-e201ac62e893_543x211.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!dBli!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc6288610-315d-4d09-a1c5-e201ac62e893_543x211.png 424w, https://substackcdn.com/image/fetch/$s_!dBli!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc6288610-315d-4d09-a1c5-e201ac62e893_543x211.png 848w, https://substackcdn.com/image/fetch/$s_!dBli!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc6288610-315d-4d09-a1c5-e201ac62e893_543x211.png 1272w, https://substackcdn.com/image/fetch/$s_!dBli!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc6288610-315d-4d09-a1c5-e201ac62e893_543x211.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!dBli!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc6288610-315d-4d09-a1c5-e201ac62e893_543x211.png" width="543" height="211" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/c6288610-315d-4d09-a1c5-e201ac62e893_543x211.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:211,&quot;width&quot;:543,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:13037,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!dBli!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc6288610-315d-4d09-a1c5-e201ac62e893_543x211.png 424w, https://substackcdn.com/image/fetch/$s_!dBli!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc6288610-315d-4d09-a1c5-e201ac62e893_543x211.png 848w, https://substackcdn.com/image/fetch/$s_!dBli!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc6288610-315d-4d09-a1c5-e201ac62e893_543x211.png 1272w, https://substackcdn.com/image/fetch/$s_!dBli!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc6288610-315d-4d09-a1c5-e201ac62e893_543x211.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!wOKb!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff361abf3-f6ea-460b-b613-1907b93fd133_543x211.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!wOKb!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff361abf3-f6ea-460b-b613-1907b93fd133_543x211.png 424w, https://substackcdn.com/image/fetch/$s_!wOKb!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff361abf3-f6ea-460b-b613-1907b93fd133_543x211.png 848w, https://substackcdn.com/image/fetch/$s_!wOKb!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff361abf3-f6ea-460b-b613-1907b93fd133_543x211.png 1272w, https://substackcdn.com/image/fetch/$s_!wOKb!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff361abf3-f6ea-460b-b613-1907b93fd133_543x211.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!wOKb!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff361abf3-f6ea-460b-b613-1907b93fd133_543x211.png" width="543" height="211" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/f361abf3-f6ea-460b-b613-1907b93fd133_543x211.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:211,&quot;width&quot;:543,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:13155,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!wOKb!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff361abf3-f6ea-460b-b613-1907b93fd133_543x211.png 424w, https://substackcdn.com/image/fetch/$s_!wOKb!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff361abf3-f6ea-460b-b613-1907b93fd133_543x211.png 848w, https://substackcdn.com/image/fetch/$s_!wOKb!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff361abf3-f6ea-460b-b613-1907b93fd133_543x211.png 1272w, https://substackcdn.com/image/fetch/$s_!wOKb!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff361abf3-f6ea-460b-b613-1907b93fd133_543x211.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>It's evident that the model demonstrates good performance, effectively reconstructing a nearly identical image from a noisy input.</p>]]></content:encoded></item><item><title><![CDATA[Benchmarking the new AWS S3 Express One Zone]]></title><description><![CDATA[At the latest AWS re:Invent (2023), AWS announced the new Amazon S3 Express One Zone Storage Class.]]></description><link>https://blog.x504.dev/p/benchmarking-the-new-aws-s3-express</link><guid isPermaLink="false">https://blog.x504.dev/p/benchmarking-the-new-aws-s3-express</guid><dc:creator><![CDATA[x504]]></dc:creator><pubDate>Fri, 05 Jan 2024 08:50:57 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!cyiz!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F408ece5f-e6d5-4031-a8d6-5f4509cc0458_656x360.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>At the latest AWS re:Invent (2023), AWS announced the new Amazon S3 Express One Zone Storage Class. This new service provides incredible new functionality for low latency applications.</p><p>With S3 Express One Zone, you have single digit millisecond access, increasing access speed up to 10x, while reducing costs by 50% compared to standard S3. Your data is redundantly stored on multiple devices within a single Availability Zone (AZ) with 99,95% of availability within a single AZ.</p><p>Until now, we had the possibility of choosing in which AWS region our S3 standard bucket would be located. With S3 Express One Zone you must select a specific AWS Availability Zone where the bucket will be created and where all your data will be saved. Data is stored in a different bucket type&#8212;an S3 directory&nbsp;bucket&#8212;which supports hundreds of thousands of requests per second. This new bucket type has a hierarchical namespace and stores object key names in a directory-like manner, as opposed to the flat key structure of traditional S3 buckets.</p><p>S3 Express introduces a new session-based authorization capability that reduces the latency associated with S3 request authorizations. This new capability can be used to create and periodically refresh your connection sessions to the new bucket type.</p><p>Let's first refresh how AWS manages the Availability Zones (AZs) in their infrastructure.</p><div class="pullquote"><p>An Availability Zone is one or more discrete data centers with redundant power, networking, and connectivity in an AWS Region. To optimize low-latency retrievals, objects in the Amazon S3 Express One Zone storage class are redundantly stored in S3 directory buckets in a single Availability Zone that's local to your compute workload. When you create a directory bucket, you choose the Availability Zone and AWS Region where your bucket will be located.</p><p>AWS maps the physical Availability Zones randomly to the Availability Zone names for each AWS account. This approach helps to distribute resources across the Availability Zones in an AWS Region, instead of resources likely being concentrated in the first Availability Zone for each Region. As a result, the Availability Zone&nbsp;<code>us-east-1a</code>&nbsp;for your AWS account might not represent the same physical location as&nbsp;<code>us-east-1a</code>&nbsp;for a different AWS account.</p></div><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!cyiz!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F408ece5f-e6d5-4031-a8d6-5f4509cc0458_656x360.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!cyiz!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F408ece5f-e6d5-4031-a8d6-5f4509cc0458_656x360.png 424w, https://substackcdn.com/image/fetch/$s_!cyiz!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F408ece5f-e6d5-4031-a8d6-5f4509cc0458_656x360.png 848w, https://substackcdn.com/image/fetch/$s_!cyiz!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F408ece5f-e6d5-4031-a8d6-5f4509cc0458_656x360.png 1272w, https://substackcdn.com/image/fetch/$s_!cyiz!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F408ece5f-e6d5-4031-a8d6-5f4509cc0458_656x360.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!cyiz!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F408ece5f-e6d5-4031-a8d6-5f4509cc0458_656x360.png" width="656" height="360" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/408ece5f-e6d5-4031-a8d6-5f4509cc0458_656x360.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:360,&quot;width&quot;:656,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:50618,&quot;alt&quot;:&quot;aws availability zones&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="aws availability zones" title="aws availability zones" srcset="https://substackcdn.com/image/fetch/$s_!cyiz!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F408ece5f-e6d5-4031-a8d6-5f4509cc0458_656x360.png 424w, https://substackcdn.com/image/fetch/$s_!cyiz!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F408ece5f-e6d5-4031-a8d6-5f4509cc0458_656x360.png 848w, https://substackcdn.com/image/fetch/$s_!cyiz!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F408ece5f-e6d5-4031-a8d6-5f4509cc0458_656x360.png 1272w, https://substackcdn.com/image/fetch/$s_!cyiz!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F408ece5f-e6d5-4031-a8d6-5f4509cc0458_656x360.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image buttonBase-GK1x3M"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image buttonBase-GK1x3M"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">Source: docs.aws.amazon.com</figcaption></figure></div><p>As today, S3 Express One Zone is supported in the following Regions and Availability Zones.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!3M4j!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa9e8f180-dc06-410b-bc8a-890cdb825352_528x449.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!3M4j!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa9e8f180-dc06-410b-bc8a-890cdb825352_528x449.png 424w, https://substackcdn.com/image/fetch/$s_!3M4j!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa9e8f180-dc06-410b-bc8a-890cdb825352_528x449.png 848w, https://substackcdn.com/image/fetch/$s_!3M4j!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa9e8f180-dc06-410b-bc8a-890cdb825352_528x449.png 1272w, https://substackcdn.com/image/fetch/$s_!3M4j!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa9e8f180-dc06-410b-bc8a-890cdb825352_528x449.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!3M4j!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa9e8f180-dc06-410b-bc8a-890cdb825352_528x449.png" width="528" height="449" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/a9e8f180-dc06-410b-bc8a-890cdb825352_528x449.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:449,&quot;width&quot;:528,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:73118,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!3M4j!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa9e8f180-dc06-410b-bc8a-890cdb825352_528x449.png 424w, https://substackcdn.com/image/fetch/$s_!3M4j!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa9e8f180-dc06-410b-bc8a-890cdb825352_528x449.png 848w, https://substackcdn.com/image/fetch/$s_!3M4j!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa9e8f180-dc06-410b-bc8a-890cdb825352_528x449.png 1272w, https://substackcdn.com/image/fetch/$s_!3M4j!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa9e8f180-dc06-410b-bc8a-890cdb825352_528x449.png 1456w" sizes="100vw"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image buttonBase-GK1x3M"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image buttonBase-GK1x3M"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p></p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://blog.x504.dev/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://blog.x504.dev/subscribe?"><span>Subscribe now</span></a></p><h3>Benchmarking</h3><p>I have decided to test this new bucket storage class and compare it with the standard one. The idea is to compare how different in terms of speed file transfers can be made.</p><p>To carry out the corresponding tests I have created two types of buckets using <a href="https://www.terraform.io/">Terraform</a>. A standard bucket and a directory bucket (Express One Zone). </p><p>For transferring the files, I&#8217;ve used the <a href="https://aws.amazon.com/cli/">AWS CLI</a> with the <a href="https://docs.aws.amazon.com/cli/latest/reference/s3/sync.html">S3 Sync</a> command to send the files from the EC2 instance to the two buckets.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!WfFs!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff928e91f-e97f-4463-b64c-04ecc7077977_519x314.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!WfFs!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff928e91f-e97f-4463-b64c-04ecc7077977_519x314.png 424w, https://substackcdn.com/image/fetch/$s_!WfFs!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff928e91f-e97f-4463-b64c-04ecc7077977_519x314.png 848w, https://substackcdn.com/image/fetch/$s_!WfFs!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff928e91f-e97f-4463-b64c-04ecc7077977_519x314.png 1272w, https://substackcdn.com/image/fetch/$s_!WfFs!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff928e91f-e97f-4463-b64c-04ecc7077977_519x314.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!WfFs!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff928e91f-e97f-4463-b64c-04ecc7077977_519x314.png" width="451" height="272.85934489402695" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/f928e91f-e97f-4463-b64c-04ecc7077977_519x314.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:314,&quot;width&quot;:519,&quot;resizeWidth&quot;:451,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!WfFs!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff928e91f-e97f-4463-b64c-04ecc7077977_519x314.png 424w, https://substackcdn.com/image/fetch/$s_!WfFs!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff928e91f-e97f-4463-b64c-04ecc7077977_519x314.png 848w, https://substackcdn.com/image/fetch/$s_!WfFs!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff928e91f-e97f-4463-b64c-04ecc7077977_519x314.png 1272w, https://substackcdn.com/image/fetch/$s_!WfFs!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff928e91f-e97f-4463-b64c-04ecc7077977_519x314.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image buttonBase-GK1x3M"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image buttonBase-GK1x3M"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p></p><p>The code in terraform is quite simple and you can see it below.</p><ul><li><p><strong>The code to create an S3 Express One Zone bucket:</strong></p></li></ul><pre><code>resource "aws_s3_directory_bucket" "example_express_bucket" {
  bucket = "example-express-bucket--use1-az4--x-s3"

  location {
    name = "use1-az4"
  }

  force_destroy = true
}</code></pre><p><em>Keep in mind that for this type of bucket, the name must be in the format: <strong>[bucket_name]--[azid]--x-s3. </strong>Where <strong>azid</strong> is the </em>Availability Zone ID.</p><p></p><ul><li><p><strong>The code to create an S3 Standard bucket:</strong></p></li></ul><pre><code>resource "aws_s3_bucket" "example_clasical_bucket" {
  bucket = "example-clasical-bucket"
  force_destroy = true
}</code></pre><p>Buckets where created successfully, we can see them on AWS GUI.</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!GHB1!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd7cf90bd-2b94-4abe-aa5e-5b51b3619225_541x212.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!GHB1!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd7cf90bd-2b94-4abe-aa5e-5b51b3619225_541x212.png 424w, https://substackcdn.com/image/fetch/$s_!GHB1!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd7cf90bd-2b94-4abe-aa5e-5b51b3619225_541x212.png 848w, https://substackcdn.com/image/fetch/$s_!GHB1!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd7cf90bd-2b94-4abe-aa5e-5b51b3619225_541x212.png 1272w, https://substackcdn.com/image/fetch/$s_!GHB1!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd7cf90bd-2b94-4abe-aa5e-5b51b3619225_541x212.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!GHB1!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd7cf90bd-2b94-4abe-aa5e-5b51b3619225_541x212.png" width="541" height="212" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/d7cf90bd-2b94-4abe-aa5e-5b51b3619225_541x212.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:212,&quot;width&quot;:541,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:37061,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!GHB1!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd7cf90bd-2b94-4abe-aa5e-5b51b3619225_541x212.png 424w, https://substackcdn.com/image/fetch/$s_!GHB1!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd7cf90bd-2b94-4abe-aa5e-5b51b3619225_541x212.png 848w, https://substackcdn.com/image/fetch/$s_!GHB1!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd7cf90bd-2b94-4abe-aa5e-5b51b3619225_541x212.png 1272w, https://substackcdn.com/image/fetch/$s_!GHB1!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd7cf90bd-2b94-4abe-aa5e-5b51b3619225_541x212.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a><figcaption class="image-caption">S3 bucket with Express One Zone storage class</figcaption></figure></div><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!JG2x!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F638a7cdc-997c-4f98-aa00-a7f578f978e4_535x240.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!JG2x!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F638a7cdc-997c-4f98-aa00-a7f578f978e4_535x240.png 424w, https://substackcdn.com/image/fetch/$s_!JG2x!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F638a7cdc-997c-4f98-aa00-a7f578f978e4_535x240.png 848w, https://substackcdn.com/image/fetch/$s_!JG2x!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F638a7cdc-997c-4f98-aa00-a7f578f978e4_535x240.png 1272w, https://substackcdn.com/image/fetch/$s_!JG2x!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F638a7cdc-997c-4f98-aa00-a7f578f978e4_535x240.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!JG2x!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F638a7cdc-997c-4f98-aa00-a7f578f978e4_535x240.png" width="535" height="240" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/638a7cdc-997c-4f98-aa00-a7f578f978e4_535x240.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:240,&quot;width&quot;:535,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:38525,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!JG2x!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F638a7cdc-997c-4f98-aa00-a7f578f978e4_535x240.png 424w, https://substackcdn.com/image/fetch/$s_!JG2x!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F638a7cdc-997c-4f98-aa00-a7f578f978e4_535x240.png 848w, https://substackcdn.com/image/fetch/$s_!JG2x!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F638a7cdc-997c-4f98-aa00-a7f578f978e4_535x240.png 1272w, https://substackcdn.com/image/fetch/$s_!JG2x!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F638a7cdc-997c-4f98-aa00-a7f578f978e4_535x240.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a><figcaption class="image-caption">S3 bucket with Standard storage class</figcaption></figure></div><p>In order to test the bandwidth speed, we have to send and/or retrieve files to the bucket from an EC2 instance. For that I&#8217;ve spin up an EC2 instance and wrote a small Shell script to create random files with specific sizes for our benchmark tests.</p><p>The Shell script must be executed passing two parameters. One is the number of files you want to generate (<strong>file_numbers</strong>) and the second one is the size for each of those files (<strong>file_size_in_bytes</strong>). </p><p>Example, to generate 100 files of 100k bytes, you execute <code>./random.sh 100 100k</code></p><p>You can see the script below.</p><pre><code>#!/bin/bash

# Check if the correct number of arguments is provided
if [ "$#" -ne 2 ]; then
    echo "Usage: $0 &lt;file_numbers&gt; &lt;file_size_in_bytes&gt;"
    echo "Example: $0 100 200k"
    exit 1
fi

file_numbers=$1
file_size=$2

for i in $(seq 1 $file_numbers)
    do
        # Generate random data and write it to the file
        dd if=/dev/urandom of=files/$i.txt bs=$file_size count=1 status=progress
    done
</code></pre><h4>Experiments</h4><p>Now, we've reached the funny part of the game. I've executed two experiments related to transmitting files from the EC2 instance to AWS S3, focusing on the assessment of writing operations.</p><p>For the experiment 1, I generate 1000 files each of 1 Mb with this command: <code>./random.sh 1000 1M</code></p><p>For experiment 2 , 50000 files were generated each of 100kb size with the following command: <code>./random.sh 50000 100k</code><br></p><p>We can see the files were created on the EC2 instance and are ready to be uploaded to AWS S3.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Fffm!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F255c4e8e-c9cb-4b22-a0ec-e8c8b64dbed3_766x390.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Fffm!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F255c4e8e-c9cb-4b22-a0ec-e8c8b64dbed3_766x390.png 424w, https://substackcdn.com/image/fetch/$s_!Fffm!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F255c4e8e-c9cb-4b22-a0ec-e8c8b64dbed3_766x390.png 848w, https://substackcdn.com/image/fetch/$s_!Fffm!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F255c4e8e-c9cb-4b22-a0ec-e8c8b64dbed3_766x390.png 1272w, https://substackcdn.com/image/fetch/$s_!Fffm!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F255c4e8e-c9cb-4b22-a0ec-e8c8b64dbed3_766x390.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Fffm!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F255c4e8e-c9cb-4b22-a0ec-e8c8b64dbed3_766x390.png" width="594" height="302.4281984334204" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/255c4e8e-c9cb-4b22-a0ec-e8c8b64dbed3_766x390.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:390,&quot;width&quot;:766,&quot;resizeWidth&quot;:594,&quot;bytes&quot;:438291,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!Fffm!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F255c4e8e-c9cb-4b22-a0ec-e8c8b64dbed3_766x390.png 424w, https://substackcdn.com/image/fetch/$s_!Fffm!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F255c4e8e-c9cb-4b22-a0ec-e8c8b64dbed3_766x390.png 848w, https://substackcdn.com/image/fetch/$s_!Fffm!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F255c4e8e-c9cb-4b22-a0ec-e8c8b64dbed3_766x390.png 1272w, https://substackcdn.com/image/fetch/$s_!Fffm!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F255c4e8e-c9cb-4b22-a0ec-e8c8b64dbed3_766x390.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image buttonBase-GK1x3M"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image buttonBase-GK1x3M"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">1000 files of 1Mb randomly generated (experiment 1)</figcaption></figure></div><p>In the case of experiment 1, we can see the files&#8217;s size:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!VBO9!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd99295a8-de36-4bb8-a429-b405ccbd5ec3_209x440.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!VBO9!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd99295a8-de36-4bb8-a429-b405ccbd5ec3_209x440.png 424w, https://substackcdn.com/image/fetch/$s_!VBO9!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd99295a8-de36-4bb8-a429-b405ccbd5ec3_209x440.png 848w, https://substackcdn.com/image/fetch/$s_!VBO9!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd99295a8-de36-4bb8-a429-b405ccbd5ec3_209x440.png 1272w, https://substackcdn.com/image/fetch/$s_!VBO9!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd99295a8-de36-4bb8-a429-b405ccbd5ec3_209x440.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!VBO9!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd99295a8-de36-4bb8-a429-b405ccbd5ec3_209x440.png" width="209" height="440" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/d99295a8-de36-4bb8-a429-b405ccbd5ec3_209x440.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:440,&quot;width&quot;:209,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:68852,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!VBO9!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd99295a8-de36-4bb8-a429-b405ccbd5ec3_209x440.png 424w, https://substackcdn.com/image/fetch/$s_!VBO9!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd99295a8-de36-4bb8-a429-b405ccbd5ec3_209x440.png 848w, https://substackcdn.com/image/fetch/$s_!VBO9!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd99295a8-de36-4bb8-a429-b405ccbd5ec3_209x440.png 1272w, https://substackcdn.com/image/fetch/$s_!VBO9!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd99295a8-de36-4bb8-a429-b405ccbd5ec3_209x440.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image buttonBase-GK1x3M"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image buttonBase-GK1x3M"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>We can confirmed files were uploaded and we can see them on AWS GUI.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!ifZ1!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6741c772-c2b3-4b35-8b29-6e8f225bddba_762x329.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!ifZ1!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6741c772-c2b3-4b35-8b29-6e8f225bddba_762x329.png 424w, https://substackcdn.com/image/fetch/$s_!ifZ1!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6741c772-c2b3-4b35-8b29-6e8f225bddba_762x329.png 848w, https://substackcdn.com/image/fetch/$s_!ifZ1!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6741c772-c2b3-4b35-8b29-6e8f225bddba_762x329.png 1272w, https://substackcdn.com/image/fetch/$s_!ifZ1!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6741c772-c2b3-4b35-8b29-6e8f225bddba_762x329.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!ifZ1!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6741c772-c2b3-4b35-8b29-6e8f225bddba_762x329.png" width="598" height="258.1916010498688" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/6741c772-c2b3-4b35-8b29-6e8f225bddba_762x329.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:329,&quot;width&quot;:762,&quot;resizeWidth&quot;:598,&quot;bytes&quot;:79255,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!ifZ1!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6741c772-c2b3-4b35-8b29-6e8f225bddba_762x329.png 424w, https://substackcdn.com/image/fetch/$s_!ifZ1!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6741c772-c2b3-4b35-8b29-6e8f225bddba_762x329.png 848w, https://substackcdn.com/image/fetch/$s_!ifZ1!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6741c772-c2b3-4b35-8b29-6e8f225bddba_762x329.png 1272w, https://substackcdn.com/image/fetch/$s_!ifZ1!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6741c772-c2b3-4b35-8b29-6e8f225bddba_762x329.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image buttonBase-GK1x3M"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image buttonBase-GK1x3M"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">files on standard bucket</figcaption></figure></div><p></p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!-xsp!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fce7ab5a6-ce3d-483e-abbe-6add041f6fb9_762x344.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!-xsp!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fce7ab5a6-ce3d-483e-abbe-6add041f6fb9_762x344.png 424w, https://substackcdn.com/image/fetch/$s_!-xsp!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fce7ab5a6-ce3d-483e-abbe-6add041f6fb9_762x344.png 848w, https://substackcdn.com/image/fetch/$s_!-xsp!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fce7ab5a6-ce3d-483e-abbe-6add041f6fb9_762x344.png 1272w, https://substackcdn.com/image/fetch/$s_!-xsp!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fce7ab5a6-ce3d-483e-abbe-6add041f6fb9_762x344.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!-xsp!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fce7ab5a6-ce3d-483e-abbe-6add041f6fb9_762x344.png" width="612" height="276.2834645669291" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/ce7ab5a6-ce3d-483e-abbe-6add041f6fb9_762x344.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:344,&quot;width&quot;:762,&quot;resizeWidth&quot;:612,&quot;bytes&quot;:92847,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!-xsp!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fce7ab5a6-ce3d-483e-abbe-6add041f6fb9_762x344.png 424w, https://substackcdn.com/image/fetch/$s_!-xsp!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fce7ab5a6-ce3d-483e-abbe-6add041f6fb9_762x344.png 848w, https://substackcdn.com/image/fetch/$s_!-xsp!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fce7ab5a6-ce3d-483e-abbe-6add041f6fb9_762x344.png 1272w, https://substackcdn.com/image/fetch/$s_!-xsp!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fce7ab5a6-ce3d-483e-abbe-6add041f6fb9_762x344.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image buttonBase-GK1x3M"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image buttonBase-GK1x3M"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">files on directory bucket</figcaption></figure></div><p>When uploading the files to S3, I measured the time it took on each experiment and the average bandwidth of the transferring operation.</p><h3>Results</h3><p>Here I present the results and finding during the experiments. On the table below we can see the results for each experiment.</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!ALRn!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F38ca1b90-bebf-4970-8cb8-3980ca4a0870_776x74.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!ALRn!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F38ca1b90-bebf-4970-8cb8-3980ca4a0870_776x74.png 424w, https://substackcdn.com/image/fetch/$s_!ALRn!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F38ca1b90-bebf-4970-8cb8-3980ca4a0870_776x74.png 848w, https://substackcdn.com/image/fetch/$s_!ALRn!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F38ca1b90-bebf-4970-8cb8-3980ca4a0870_776x74.png 1272w, https://substackcdn.com/image/fetch/$s_!ALRn!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F38ca1b90-bebf-4970-8cb8-3980ca4a0870_776x74.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!ALRn!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F38ca1b90-bebf-4970-8cb8-3980ca4a0870_776x74.png" width="776" height="74" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/38ca1b90-bebf-4970-8cb8-3980ca4a0870_776x74.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:74,&quot;width&quot;:776,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:17820,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!ALRn!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F38ca1b90-bebf-4970-8cb8-3980ca4a0870_776x74.png 424w, https://substackcdn.com/image/fetch/$s_!ALRn!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F38ca1b90-bebf-4970-8cb8-3980ca4a0870_776x74.png 848w, https://substackcdn.com/image/fetch/$s_!ALRn!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F38ca1b90-bebf-4970-8cb8-3980ca4a0870_776x74.png 1272w, https://substackcdn.com/image/fetch/$s_!ALRn!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F38ca1b90-bebf-4970-8cb8-3980ca4a0870_776x74.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>We can notice that there are no big difference on first experiment. Having 17 seconds v.s. 15 seconds is not a huge difference and this is because we sent 1000 files of 1Mb and t<em>he new storage class (S3 Express One Zone) provides better performance when transferring smaller objects.</em> We can confirm this on second experiment when sending more files and more smaller than on experiment 1 and we gain the double of time for the transaction time.</p><p>The reason is because latency usually impacts small files much more than larger files as we can constate in our experiments.</p><p>But, I wasn&#8217;t completely happy with the results. The docummentation mentioned that we can obtain up to 10x speed but I only got 2x. After further investigating I realize that we can tune the AWS Sync command to improve performance by modifying the value of <a href="https://awscli.amazonaws.com/v2/documentation/api/latest/topic/s3-config.html#max-concurrent-requests">max_concurrent_requests</a>. This value sets the number of requests that you can send to Amazon S3 at a time. The default value is 10, but you can increase it to a higher value.</p><p>Then I re-ran the second experiment and obtained better results.</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Zx6n!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F03727715-3f0f-40f7-a90a-0f6c882e82b3_773x101.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Zx6n!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F03727715-3f0f-40f7-a90a-0f6c882e82b3_773x101.png 424w, https://substackcdn.com/image/fetch/$s_!Zx6n!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F03727715-3f0f-40f7-a90a-0f6c882e82b3_773x101.png 848w, https://substackcdn.com/image/fetch/$s_!Zx6n!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F03727715-3f0f-40f7-a90a-0f6c882e82b3_773x101.png 1272w, https://substackcdn.com/image/fetch/$s_!Zx6n!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F03727715-3f0f-40f7-a90a-0f6c882e82b3_773x101.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Zx6n!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F03727715-3f0f-40f7-a90a-0f6c882e82b3_773x101.png" width="773" height="101" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/03727715-3f0f-40f7-a90a-0f6c882e82b3_773x101.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:101,&quot;width&quot;:773,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:24803,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!Zx6n!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F03727715-3f0f-40f7-a90a-0f6c882e82b3_773x101.png 424w, https://substackcdn.com/image/fetch/$s_!Zx6n!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F03727715-3f0f-40f7-a90a-0f6c882e82b3_773x101.png 848w, https://substackcdn.com/image/fetch/$s_!Zx6n!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F03727715-3f0f-40f7-a90a-0f6c882e82b3_773x101.png 1272w, https://substackcdn.com/image/fetch/$s_!Zx6n!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F03727715-3f0f-40f7-a90a-0f6c882e82b3_773x101.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>We gain 5x on performance!. That&#8217;s great.</p><p>To conclude:</p><ul><li><p>The new S3 Express One Zone storage class (a.k.a Directory Bucket) better perform on large amount of smaller files.</p></li><li><p>AWS S3 batch operations will get more beneficial of it.</p></li><li><p>I&#8217;ve performed the experiments with AWS CLI, but if you have an application that use, for instance the AWS SDK and can perform batch operations in parallel, then this new storage class is a good candidate to gain performance.</p></li><li><p>To gain the most beneficial of it, you must set your workload on the same Availability zone as your Directory bucket is located. </p></li><li><p>Be aware that the Directory bucket structure is different than the traditional S3 buckets.</p><p></p></li></ul><div><hr></div><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://blog.x504.dev/p/benchmarking-the-new-aws-s3-express?utm_source=substack&utm_medium=email&utm_content=share&action=share&quot;,&quot;text&quot;:&quot;Share&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://blog.x504.dev/p/benchmarking-the-new-aws-s3-express?utm_source=substack&utm_medium=email&utm_content=share&action=share"><span>Share</span></a></p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://blog.x504.dev/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Thanks for reading! Subscribe for free to receive new posts and support my work.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><p></p>]]></content:encoded></item></channel></rss>