<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Zero5 Works</title>
    <description>The latest articles on DEV Community by Zero5 Works (@zero5works).</description>
    <link>https://dev.to/zero5works</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4282337%2Fb0aa1898-ff1c-4922-b7d4-26e84b0db540.png</url>
      <title>DEV Community: Zero5 Works</title>
      <link>https://dev.to/zero5works</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/zero5works"/>
    <language>en</language>
    <item>
      <title>LatentSync 1.6 on a free Kaggle T4: fp32 OOM vs fp16 + VAE slicing at 7.56 GiB</title>
      <dc:creator>Zero5 Works</dc:creator>
      <pubDate>Fri, 04 Dec 2026 09:12:28 +0000</pubDate>
      <link>https://dev.to/zero5works/latentsync-16-on-a-free-kaggle-t4-fp32-oom-vs-fp16-vae-slicing-at-756-gib-3gkh</link>
      <guid>https://dev.to/zero5works/latentsync-16-on-a-free-kaggle-t4-fp32-oom-vs-fp16-vae-slicing-at-756-gib-3gkh</guid>
      <description>&lt;p&gt;LatentSync 1.6 ran out of memory on a free Kaggle T4. PyTorch held 13.28 GiB and asked for 2 more. With fp16 and VAE slicing, the same clip finished all 242 frames at a 7.56 GiB peak.&lt;/p&gt;

&lt;p&gt;The fix is two lines in my own runner, and LatentSync's code stays untouched. Every number below comes from one run: Version #4 of my public &lt;a href="https://www.kaggle.com/code/ardaboyac/latentsync-1-6-on-a-free-kaggle-t4-7-73-gib-peak" rel="noopener noreferrer"&gt;Kaggle notebook for LatentSync 1.6 on a free T4&lt;/a&gt;. The notebook's title carries the peak from my own private clip. This post sticks to the public demo run.&lt;/p&gt;

&lt;h2&gt;
  
  
  The setup
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Model:&lt;/strong&gt; LatentSync 1.6 at commit &lt;code&gt;a229c39&lt;/code&gt;. Its README lists 18 GB of VRAM for inference.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;GPU:&lt;/strong&gt; Kaggle T4 ×2. PyTorch sees 14.56 GiB per card, compute capability 7.5.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Input:&lt;/strong&gt; the upstream demo clip &lt;code&gt;demo1&lt;/code&gt;. 10 s, 1080×1920, 25 fps.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Settings:&lt;/strong&gt; 10 steps, guidance 1.5, DeepCache on, seed 1247.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Pinned:&lt;/strong&gt; torch 2.5.1+cu121, diffusers 0.32.2, mediapipe 0.10.14, in a separate Python 3.10 env built with &lt;code&gt;uv&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I ran two configs in parallel, one per T4. A follows the upstream dtype rule. B is my fix.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why a T4 runs out of memory
&lt;/h2&gt;

&lt;p&gt;I found two causes by reading the code at &lt;code&gt;a229c39&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The first one is the dtype rule in &lt;code&gt;scripts/inference.py&lt;/code&gt;. My runner reproduces it like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;dtype&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;torch&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;float16&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;torch&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;cuda&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get_device_capability&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;7&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="n"&gt;torch&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;float32&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A T4 is compute capability 7.5, so the major version is 7. Both the UNet and the VAE load in fp32.&lt;/p&gt;

&lt;p&gt;The second one is the VAE decode. &lt;code&gt;LipsyncPipeline&lt;/code&gt; has &lt;code&gt;enable_vae_slicing()&lt;/code&gt;, but nothing calls it. So the VAE decodes 16 frames at 512×512 in one pass.&lt;/p&gt;

&lt;h2&gt;
  
  
  The fix
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;dtype&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;torch&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;float16&lt;/span&gt;          &lt;span class="c1"&gt;# instead of the capability check&lt;/span&gt;
&lt;span class="n"&gt;pipeline&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;enable_vae_slicing&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c1"&gt;# decode one frame at a time&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I also set &lt;code&gt;PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True&lt;/code&gt; against fragmentation. B gets all three; A gets none.&lt;/p&gt;

&lt;h2&gt;
  
  
  Results: Version #4 (run 377539135)
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;A: upstream rule&lt;/th&gt;
&lt;th&gt;B: fp16 + VAE slicing&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;dtype&lt;/td&gt;
&lt;td&gt;float32&lt;/td&gt;
&lt;td&gt;float16&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;VAE slicing&lt;/td&gt;
&lt;td&gt;no&lt;/td&gt;
&lt;td&gt;yes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;status&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;OOM&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;ok, 242/242 frames&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;weights in VRAM&lt;/td&gt;
&lt;td&gt;5.21 GiB&lt;/td&gt;
&lt;td&gt;2.66 GiB&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;peak reserved&lt;/td&gt;
&lt;td&gt;13.48 GiB&lt;/td&gt;
&lt;td&gt;7.56 GiB&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;peak allocated&lt;/td&gt;
&lt;td&gt;13.28 GiB&lt;/td&gt;
&lt;td&gt;6.78 GiB&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;nvidia-smi peak&lt;/td&gt;
&lt;td&gt;13977 MiB&lt;/td&gt;
&lt;td&gt;7909 MiB&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;system RAM peak (RSS)&lt;/td&gt;
&lt;td&gt;10.34 GiB&lt;/td&gt;
&lt;td&gt;10.49 GiB&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;speed&lt;/td&gt;
&lt;td&gt;n/a&lt;/td&gt;
&lt;td&gt;0.557 frames/s&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;wall time&lt;/td&gt;
&lt;td&gt;68.0 s&lt;/td&gt;
&lt;td&gt;467.1 s&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Peak VRAM here is &lt;code&gt;torch.cuda.max_memory_reserved()&lt;/code&gt;. &lt;code&gt;nvidia-smi&lt;/code&gt; also counts the CUDA context, so it reads higher in both runs.&lt;/p&gt;

&lt;p&gt;What I read from it:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A died in the first inference batch. The error said it tried to allocate 2.00 GiB with 962.81 MiB free. PyTorch already held 13.28 GiB, so fp32 with a full-batch VAE decode needs at least 15.28 GiB. The card has 14.56 GiB.&lt;/li&gt;
&lt;li&gt;Weights alone dropped from 5.21 to 2.66 GiB in fp16. That's 1.96× smaller.&lt;/li&gt;
&lt;li&gt;B peaked at 7.56 GiB reserved, about half of the 14.56 GiB PyTorch sees.&lt;/li&gt;
&lt;li&gt;0.557 frames/s counts the whole pipeline call: face prep, diffusion, VAE decode, paste-back and writing. The 242 frames took 434.6 s.&lt;/li&gt;
&lt;li&gt;System RAM barely changed between the two. Both peaked a little above 10.3 GiB.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The whole kernel took 611.2 s. Setup was 1.5 s for the clone, 49.7 s for dependencies and 58.0 s for weights with sha256 checks.&lt;/p&gt;

&lt;h2&gt;
  
  
  The bug that stopped Version #3
&lt;/h2&gt;

&lt;p&gt;Version #3 never reached the two runs. It stopped at an import check.&lt;/p&gt;

&lt;p&gt;Kaggle sets &lt;code&gt;MPLBACKEND=module://matplotlib_inline.backend_inline&lt;/code&gt; in the notebook. I run LatentSync in a separate Python 3.10 env, as a child process, and the child inherited that variable. MediaPipe imports &lt;code&gt;matplotlib.pyplot&lt;/code&gt;, and the 3.10 env doesn't have &lt;code&gt;matplotlib_inline&lt;/code&gt;. So the import failed.&lt;/p&gt;

&lt;p&gt;The fix is a clean environment for every child process:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="no"&gt;LEAKS&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"MPLBACKEND"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"PYTHONPATH"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"PYTHONHOME"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"PYTHONSTARTUP"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"PYTHONUSERBASE"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="no"&gt;BASE_ENV&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;k&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;v&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;k&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;v&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;environ&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;items&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;k&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="s2"&gt;"MPLBACKEND"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"MPLBACKEND"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Agg"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="no"&gt;PY_ENV&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;k&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;v&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;k&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;v&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;environ&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;items&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;k&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="no"&gt;LEAKS&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
          &lt;span class="s2"&gt;"MPLBACKEND"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Agg"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"PYTHONNOUSERSITE"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"1"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Every child gets the &lt;code&gt;Agg&lt;/code&gt; backend. Children from the 3.10 env also drop the notebook's path and startup settings. With this change, Version #4 finished clean on the first try.&lt;/p&gt;

&lt;p&gt;The notebook's environment variables follow you into any second Python env you start from it. I didn't expect that one.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why MediaPipe instead of InsightFace
&lt;/h2&gt;

&lt;p&gt;LatentSync finds faces with InsightFace &lt;code&gt;buffalo_l&lt;/code&gt;, and those models are licensed for non-commercial use only. LatentSync's alignment reads just three points: left brow, right brow and nose center. So I map MediaPipe FaceLandmarker's 478 landmarks to those three points. MediaPipe's code and model are Apache-2.0. The notebook has the module and explains how I fitted the mapping.&lt;/p&gt;

&lt;h2&gt;
  
  
  What this run doesn't show
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;One run per config. I didn't repeat runs, so there's no variance.&lt;/li&gt;
&lt;li&gt;No sync quality score. The notebook doesn't compute LSE-C, so this run says nothing about lip-sync quality.&lt;/li&gt;
&lt;li&gt;One 10 s demo clip. I didn't test long videos in this run.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Reproducing it
&lt;/h2&gt;

&lt;p&gt;The &lt;a href="https://www.kaggle.com/code/ardaboyac/latentsync-1-6-on-a-free-kaggle-t4-7-73-gib-peak" rel="noopener noreferrer"&gt;notebook&lt;/a&gt; pins the LatentSync commit, the Hugging Face revisions and the sha256 of every weight file. It also writes &lt;code&gt;freeze.txt&lt;/code&gt; with every installed package. It expects GPU T4 ×2 with internet on. With one GPU, A runs after B.&lt;/p&gt;

&lt;p&gt;The config cell also takes your own clip through &lt;code&gt;OWN_VIDEO&lt;/code&gt; and &lt;code&gt;OWN_AUDIO&lt;/code&gt;. I'd only use footage you own or have consent for.&lt;/p&gt;

&lt;p&gt;I drafted this post with AI help. Every measurement in it comes from the raw output of Version #4.&lt;/p&gt;

&lt;p&gt;If you've run LatentSync 1.6 on a 16 GB card, what peak did you see?&lt;/p&gt;

</description>
      <category>machinelearning</category>
      <category>gpu</category>
      <category>python</category>
      <category>pytorch</category>
    </item>
  </channel>
</rss>
