<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>GPU on ByF (BaiFan) · Daily Deep Think</title>
    <link>https://blog.baifan.site/en/tags/gpu/</link>
    <description>Recent content in GPU on ByF (BaiFan) · Daily Deep Think</description>
    <generator>Hugo -- gohugo.io</generator>
    <language>en</language>
    <managingEditor>blog@baifan.site (ByF (BaiFan))</managingEditor>
    <webMaster>blog@baifan.site (ByF (BaiFan))</webMaster>
    <copyright>CC BY-NC 4.0</copyright>
    <lastBuildDate>Wed, 20 Aug 2025 14:00:00 +0800</lastBuildDate><atom:link href="https://blog.baifan.site/en/tags/gpu/index.xml" rel="self" type="application/rss+xml" />
    
    <item>
      <title>CPU, GPU, and Training Large Language Models</title>
      <link>https://blog.baifan.site/en/gpu-accelerated-training-cuda-complete-guide/</link>
      <pubDate>Wed, 20 Aug 2025 14:00:00 +0800</pubDate>
      <author>blog@baifan.site (ByF (BaiFan))</author>
      <guid>https://blog.baifan.site/en/gpu-accelerated-training-cuda-complete-guide/</guid>
      <description>&lt;h1 class=&#34;relative group&#34;&gt;AI Tutorial: CPU/GPU and Large Model Training&#xA;    &lt;div id=&#34;ai-tutorial-cpugpu-and-large-model-training&#34; class=&#34;anchor&#34;&gt;&lt;/div&gt;&#xA;    &#xA;    &lt;span&#xA;        class=&#34;absolute top-0 w-6 transition-opacity opacity-0 -start-6 not-prose group-hover:opacity-100 select-none&#34;&gt;&#xA;        &lt;a class=&#34;text-primary-300 dark:text-neutral-700 !no-underline&#34; href=&#34;#ai-tutorial-cpugpu-and-large-model-training&#34; aria-label=&#34;Anchor&#34;&gt;#&lt;/a&gt;&#xA;    &lt;/span&gt;&#xA;    &#xA;&lt;/h1&gt;&#xA;&lt;blockquote&gt;&lt;p&gt;This is a highly condensed reference: clearly structured, right to the point — covering CPU/GPU fundamentals, tensors and numerical precision, CUDA and PyTorch in practice, hardware selection, common interview questions, and a debugging checklist.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&lt;hr&gt;&#xA;&#xA;&lt;h2 class=&#34;relative group&#34;&gt;0. Quick Overview (30 Seconds)&#xA;    &lt;div id=&#34;0-quick-overview-30-seconds&#34; class=&#34;anchor&#34;&gt;&lt;/div&gt;&#xA;    &#xA;    &lt;span&#xA;        class=&#34;absolute top-0 w-6 transition-opacity opacity-0 -start-6 not-prose group-hover:opacity-100 select-none&#34;&gt;&#xA;        &lt;a class=&#34;text-primary-300 dark:text-neutral-700 !no-underline&#34; href=&#34;#0-quick-overview-30-seconds&#34; aria-label=&#34;Anchor&#34;&gt;#&lt;/a&gt;&#xA;    &lt;/span&gt;&#xA;    &#xA;&lt;/h2&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;strong&gt;CPU vs GPU&lt;/strong&gt;: CPUs excel at &lt;strong&gt;general-purpose/sequential&lt;/strong&gt; work; GPUs excel at &lt;strong&gt;massive parallelism&lt;/strong&gt; (matrices/vectors).&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;Large models need GPUs&lt;/strong&gt;: training/inference is fundamentally matrix multiplication and parallelization — exactly what a GPU&amp;rsquo;s high concurrency + high-bandwidth memory deliver.&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;Tensors and precision&lt;/strong&gt;: all data becomes tensors; precision (FP16/FP8) and &lt;strong&gt;quantization&lt;/strong&gt; (INT8/INT4) trade speed/VRAM against quality.&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;The PyTorch GPU mantra&lt;/strong&gt;: &lt;code&gt;device = &amp;quot;cuda&amp;quot; if ...; model.to(device); data.to(device)&lt;/code&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;Pick a GPU by VRAM first&lt;/strong&gt;: VRAM first, then bandwidth/compute; for production, prefer &lt;strong&gt;full-strength high-quality models&lt;/strong&gt; or cloud-hosted APIs.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;h2 class=&#34;relative group&#34;&gt;1. CPU vs GPU: Differences, Workloads, and Analogies&#xA;    &lt;div id=&#34;1-cpu-vs-gpu-differences-workloads-and-analogies&#34; class=&#34;anchor&#34;&gt;&lt;/div&gt;&#xA;    &#xA;    &lt;span&#xA;        class=&#34;absolute top-0 w-6 transition-opacity opacity-0 -start-6 not-prose group-hover:opacity-100 select-none&#34;&gt;&#xA;        &lt;a class=&#34;text-primary-300 dark:text-neutral-700 !no-underline&#34; href=&#34;#1-cpu-vs-gpu-differences-workloads-and-analogies&#34; aria-label=&#34;Anchor&#34;&gt;#&lt;/a&gt;&#xA;    &lt;/span&gt;&#xA;    &#xA;&lt;/h2&gt;&#xA;&#xA;&lt;h3 class=&#34;relative group&#34;&gt;1.1 The One-Line Comparison&#xA;    &lt;div id=&#34;11-the-one-line-comparison&#34; class=&#34;anchor&#34;&gt;&lt;/div&gt;&#xA;    &#xA;    &lt;span&#xA;        class=&#34;absolute top-0 w-6 transition-opacity opacity-0 -start-6 not-prose group-hover:opacity-100 select-none&#34;&gt;&#xA;        &lt;a class=&#34;text-primary-300 dark:text-neutral-700 !no-underline&#34; href=&#34;#11-the-one-line-comparison&#34; aria-label=&#34;Anchor&#34;&gt;#&lt;/a&gt;&#xA;    &lt;/span&gt;&#xA;    &#xA;&lt;/h3&gt;&#xA;&lt;table&gt;&#xA;&#x9;&lt;thead&gt;&#xA;&#x9;&#x9;&#x9;&lt;tr&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;th&gt;Dimension&lt;/th&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;th&gt;CPU&lt;/th&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;th&gt;GPU&lt;/th&gt;&#xA;&#x9;&#x9;&#x9;&lt;/tr&gt;&#xA;&#x9;&lt;/thead&gt;&#xA;&#x9;&lt;tbody&gt;&#xA;&#x9;&#x9;&#x9;&lt;tr&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;Architecture&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;Few cores, complex control flow&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;Massive small cores, SIMT parallelism&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&lt;/tr&gt;&#xA;&#x9;&#x9;&#x9;&lt;tr&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;Excels at&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;Branching/system tasks/small-scale compute&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;Matrix multiplication, convolution, attention, graphics rendering&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&lt;/tr&gt;&#xA;&#x9;&#x9;&#x9;&lt;tr&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;Task model&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;Time-sliced, low-latency switching&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;Batch- and throughput-oriented&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&lt;/tr&gt;&#xA;&#x9;&#x9;&#x9;&lt;tr&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;Typical use&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;Business logic, scheduling, I/O&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;Main training/inference operators (GEMM, Conv, etc.)&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&lt;/tr&gt;&#xA;&#x9;&lt;/tbody&gt;&#xA;&lt;/table&gt;&#xA;&#xA;&lt;h3 class=&#34;relative group&#34;&gt;1.2 An Intuitive Analogy&#xA;    &lt;div id=&#34;12-an-intuitive-analogy&#34; class=&#34;anchor&#34;&gt;&lt;/div&gt;&#xA;    &#xA;    &lt;span&#xA;        class=&#34;absolute top-0 w-6 transition-opacity opacity-0 -start-6 not-prose group-hover:opacity-100 select-none&#34;&gt;&#xA;        &lt;a class=&#34;text-primary-300 dark:text-neutral-700 !no-underline&#34; href=&#34;#12-an-intuitive-analogy&#34; aria-label=&#34;Anchor&#34;&gt;#&lt;/a&gt;&#xA;    &lt;/span&gt;&#xA;    &#xA;&lt;/h3&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;strong&gt;CPU = a veteran expert&lt;/strong&gt;: meticulous thinking, does one thing at a time with fast switching.&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;GPU = a massive army&lt;/strong&gt;: hordes of soldiers working simultaneously — built for parallel &lt;strong&gt;homogeneous small tasks&lt;/strong&gt;.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;h3 class=&#34;relative group&#34;&gt;1.3 Optional Mermaid Diagram (CPU Execution vs GPU Parallelism)&#xA;    &lt;div id=&#34;13-optional-mermaid-diagram-cpu-execution-vs-gpu-parallelism&#34; class=&#34;anchor&#34;&gt;&lt;/div&gt;&#xA;    &#xA;    &lt;span&#xA;        class=&#34;absolute top-0 w-6 transition-opacity opacity-0 -start-6 not-prose group-hover:opacity-100 select-none&#34;&gt;&#xA;        &lt;a class=&#34;text-primary-300 dark:text-neutral-700 !no-underline&#34; href=&#34;#13-optional-mermaid-diagram-cpu-execution-vs-gpu-parallelism&#34; aria-label=&#34;Anchor&#34;&gt;#&lt;/a&gt;&#xA;    &lt;/span&gt;&#xA;    &#xA;&lt;/h3&gt;&#xA;&lt;div class=&#34;highlight-wrapper&#34;&gt;&lt;div class=&#34;highlight&#34;&gt;&lt;div class=&#34;chroma&#34;&gt;&#xA;&lt;table class=&#34;lntable&#34;&gt;&lt;tr&gt;&lt;td class=&#34;lntd&#34;&gt;&#xA;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code&gt;&lt;span class=&#34;lnt&#34;&gt; 1&#xA;&lt;/span&gt;&lt;span class=&#34;lnt&#34;&gt; 2&#xA;&lt;/span&gt;&lt;span class=&#34;lnt&#34;&gt; 3&#xA;&lt;/span&gt;&lt;span class=&#34;lnt&#34;&gt; 4&#xA;&lt;/span&gt;&lt;span class=&#34;lnt&#34;&gt; 5&#xA;&lt;/span&gt;&lt;span class=&#34;lnt&#34;&gt; 6&#xA;&lt;/span&gt;&lt;span class=&#34;lnt&#34;&gt; 7&#xA;&lt;/span&gt;&lt;span class=&#34;lnt&#34;&gt; 8&#xA;&lt;/span&gt;&lt;span class=&#34;lnt&#34;&gt; 9&#xA;&lt;/span&gt;&lt;span class=&#34;lnt&#34;&gt;10&#xA;&lt;/span&gt;&lt;span class=&#34;lnt&#34;&gt;11&#xA;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&#xA;&lt;td class=&#34;lntd&#34;&gt;&#xA;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-fallback&#34; data-lang=&#34;fallback&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;flowchart LR&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    subgraph CPU[&amp;#34;CPU (sequential/few cores)&amp;#34;]&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;      A1[Task1-SliceA] --&amp;gt; A2[Task2-SliceB] --&amp;gt; A3[Task3-SliceC]&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    end&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    subgraph GPU[&amp;#34;GPU (parallel/many cores)&amp;#34;]&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;      B1[Element1 compute]:::p&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;      B2[Element2 compute]:::p&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;      B3[Element3 compute]:::p&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;      B4[Element4 compute]:::p&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    end&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    classDef p fill:#e9f5ff,stroke:#3b82f6,stroke-width:1px;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&#xA;&lt;/div&gt;&#xA;&lt;/div&gt;&lt;/div&gt;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;h2 class=&#34;relative group&#34;&gt;2. Tensors, Precision, and Quantization (with Examples)&#xA;    &lt;div id=&#34;2-tensors-precision-and-quantization-with-examples&#34; class=&#34;anchor&#34;&gt;&lt;/div&gt;&#xA;    &#xA;    &lt;span&#xA;        class=&#34;absolute top-0 w-6 transition-opacity opacity-0 -start-6 not-prose group-hover:opacity-100 select-none&#34;&gt;&#xA;        &lt;a class=&#34;text-primary-300 dark:text-neutral-700 !no-underline&#34; href=&#34;#2-tensors-precision-and-quantization-with-examples&#34; aria-label=&#34;Anchor&#34;&gt;#&lt;/a&gt;&#xA;    &lt;/span&gt;&#xA;    &#xA;&lt;/h2&gt;&#xA;&#xA;&lt;h3 class=&#34;relative group&#34;&gt;2.1 Tensor Hierarchy&#xA;    &lt;div id=&#34;21-tensor-hierarchy&#34; class=&#34;anchor&#34;&gt;&lt;/div&gt;&#xA;    &#xA;    &lt;span&#xA;        class=&#34;absolute top-0 w-6 transition-opacity opacity-0 -start-6 not-prose group-hover:opacity-100 select-none&#34;&gt;&#xA;        &lt;a class=&#34;text-primary-300 dark:text-neutral-700 !no-underline&#34; href=&#34;#21-tensor-hierarchy&#34; aria-label=&#34;Anchor&#34;&gt;#&lt;/a&gt;&#xA;    &lt;/span&gt;&#xA;    &#xA;&lt;/h3&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;strong&gt;0D&lt;/strong&gt;: scalar &lt;code&gt;3.14&lt;/code&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;1D&lt;/strong&gt;: vector &lt;code&gt;[1,2,3]&lt;/code&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;2D&lt;/strong&gt;: matrix (e.g. a 3×3 table)&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;3D+&lt;/strong&gt;: still called a tensor (e.g. &lt;code&gt;batch×channel×height×width&lt;/code&gt;)&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;&lt;strong&gt;Image example&lt;/strong&gt;: a batch of 32 224×224 RGB images → &lt;code&gt;32×3×224×224&lt;/code&gt; (or &lt;code&gt;N×H×W×C&lt;/code&gt;, depending on the framework).&lt;/p&gt;</description>
      
    </item>
    
  </channel>
</rss>
