<?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: Phoenix Labs</title>
    <description>The latest articles on DEV Community by Phoenix Labs (@thekillsquad007).</description>
    <link>https://dev.to/thekillsquad007</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%2F4227973%2Fe0a0c3f2-7380-4555-8183-fc8ff1294ed7.png</url>
      <title>DEV Community: Phoenix Labs</title>
      <link>https://dev.to/thekillsquad007</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/thekillsquad007"/>
    <language>en</language>
    <item>
      <title>PSNR rewards blur: what fine-tuning a video upscaler taught us about measuring quality</title>
      <dc:creator>Phoenix Labs</dc:creator>
      <pubDate>Wed, 25 Nov 2026 09:00:27 +0000</pubDate>
      <link>https://dev.to/thekillsquad007/psnr-rewards-blur-what-fine-tuning-a-video-upscaler-taught-us-about-measuring-quality-2324</link>
      <guid>https://dev.to/thekillsquad007/psnr-rewards-blur-what-fine-tuning-a-video-upscaler-taught-us-about-measuring-quality-2324</guid>
      <description>&lt;p&gt;We spent a stretch of November fine-tuning a diffusion video upscaler on public-domain footage, trying to make old tapes restore more faithfully. The interesting result wasn't that we succeeded. It was that our first attempt "won" on the standard metric by quietly making the picture worse.&lt;/p&gt;

&lt;p&gt;That failure is worth writing up, because it's a trap that shows up anywhere image quality is measured with PSNR.&lt;/p&gt;

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

&lt;p&gt;The model is a one-step diffusion upscaler with a frozen transformer and decoder. We trained a small LoRA on the transformer's attention and feed-forward layers: about 16 million parameters, a few tens of megabytes, and it merges back into the weights afterwards, so inference cost doesn't change.&lt;/p&gt;

&lt;p&gt;Training pairs came from public-domain sources only: NASA's image and video library, and Wikimedia Commons material tagged public domain, CC0, or CC BY. We deliberately avoided sources with murky reuse terms. Pairs were generated at 4x degradation and a 256 px crop, which is the minimum the model's window attention allows.&lt;/p&gt;

&lt;p&gt;The loss combined three terms: a Charbonnier pixel loss, a low-frequency match on 8x8 pooled images, and a temporal-difference match to keep consecutive frames consistent. The goal was faithfulness, not sharpness.&lt;/p&gt;

&lt;h2&gt;
  
  
  The result that looked like a win
&lt;/h2&gt;

&lt;p&gt;We held out eight videos with fixed crops that were never trained on. After 100 steps, the fine-tuned model had clearly improved:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Low-frequency error: &lt;strong&gt;0.0453 → 0.0336&lt;/strong&gt; (closer to the clean original)&lt;/li&gt;
&lt;li&gt;PSNR: &lt;strong&gt;26.66 → 28.72&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Texture energy: &lt;strong&gt;1.12 → 0.24&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Two out of three looked great. That third number is the problem.&lt;/p&gt;

&lt;p&gt;We measure "texture" as the ratio of total Laplacian energy in the output to the clean frames. A value of 1.0 means the output has roughly the same fine detail as the original; plain bicubic upscaling scores about 0.12. Our model had dropped from 1.12 to 0.24. It had learned to blur.&lt;/p&gt;

&lt;p&gt;PSNR had gone up precisely because of that blur. When you optimize pixel error, the safest bet for uncertain detail is to predict the mean, and the mean of a textured region is a smooth patch. The metric wasn't wrong; it was measuring exactly what we asked it to. We'd just asked for the wrong thing.&lt;/p&gt;

&lt;h2&gt;
  
  
  Fixing the objective
&lt;/h2&gt;

&lt;p&gt;We added a per-8x8-patch texture-energy match term to the loss and restarted. Now a checkpoint only counts as better if texture stays near 1.0. With that constraint the low-frequency error still improved (-0.009 at step 100, another -0.0017 at step 200) but detail only drifted to 0.85 and 0.74, and the later run pushes texture weight harder to hold it.&lt;/p&gt;

&lt;p&gt;The broader lesson: if you care about perceived detail, track it explicitly. Don't assume PSNR implies it. We now treat texture energy as a gate alongside the error metrics, and we validate on fixed crops with fixed noise so the numbers are comparable across runs.&lt;/p&gt;

&lt;h2&gt;
  
  
  A note on engine choice
&lt;/h2&gt;

&lt;p&gt;While this was running, a newer version of the same model family was released under an Apache-2.0 licence. We scored both on the same held-out clips. The newer engine won on every quality column and invented substantially less texture, even though it was slower per clip. That's a good reminder to re-benchmark when a model family updates: work spent fine-tuning the previous engine can be overtaken by a checkpoint you didn't train.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why this matters for restoration
&lt;/h2&gt;

&lt;p&gt;Old footage has two failure modes that pull in opposite directions. Noise and compression damage want smoothing; real texture and faces want preservation. An optimizer left to its own devices will pick smoothing, because that's the low-error solution, and the result looks like a waxy version of the original.&lt;/p&gt;

&lt;p&gt;That's the constraint we build around in &lt;a href="https://phoenixlabs.space/upscaler" rel="noopener noreferrer"&gt;Phoenix Upscaler&lt;/a&gt;: generative detail is a donor, blended onto a source-safe base, rather than the whole picture. The &lt;a href="https://phoenixlabs.space/upscaler-guide" rel="noopener noreferrer"&gt;guide&lt;/a&gt; explains the quality modes, and we wrote up the reasoning behind the one-time pricing on the &lt;a href="https://phoenixlabs.space/topaz-video-ai-alternative" rel="noopener noreferrer"&gt;Topaz alternative page&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;If you're training or evaluating an image or video model, add one metric that measures the thing you actually care about. Otherwise your loss function will quietly define quality for you.&lt;/p&gt;

</description>
      <category>video</category>
    </item>
    <item>
      <title>Three settings that made AMD video upscaling 2-3x faster (without changing the picture)</title>
      <dc:creator>Phoenix Labs</dc:creator>
      <pubDate>Wed, 25 Nov 2026 08:58:43 +0000</pubDate>
      <link>https://dev.to/thekillsquad007/three-settings-that-made-amd-video-upscaling-2-3x-faster-without-changing-the-picture-4mpn</link>
      <guid>https://dev.to/thekillsquad007/three-settings-that-made-amd-video-upscaling-2-3x-faster-without-changing-the-picture-4mpn</guid>
      <description>&lt;p&gt;A while back I wrote about getting FlashVSR, a diffusion video upscaler, running on an RX 7800 XT through WSL2 and ROCm. That post was about making it work at all. This one is about making it fast.&lt;/p&gt;

&lt;p&gt;The three changes below all came from profiling real jobs, not from guessing. Each one left the output bit-identical, which mattered: this is a restoration tool, so "faster but different" is not a win. Together they took a 4x 240p job from roughly 680 seconds to 270, and a 2x job from 188 to 86.&lt;/p&gt;

&lt;p&gt;I use all three in &lt;a href="https://phoenixlabs.space/upscaler" rel="noopener noreferrer"&gt;Phoenix Upscaler&lt;/a&gt;, but they apply to any PyTorch diffusion pipeline on RDNA3.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Turn off cuDNN benchmark
&lt;/h2&gt;

&lt;p&gt;PyTorch's &lt;code&gt;torch.backends.cudnn.benchmark = True&lt;/code&gt; sounds like a free speedup. On ROCm with MIOpen behind it, it is not. With benchmark on, MIOpen times every candidate kernel for each convolution shape in every new worker process. One of the candidates is a naive convolution that takes about five seconds, and there is a new shape to time every time the decoder sees something slightly different.&lt;/p&gt;

&lt;p&gt;On a two-minute job that added up to around 80 seconds of pure kernel selection. At 4x it was closer to 330 seconds. The kicker: after all that timing, the output was bit-identical to having benchmark off.&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;torch&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;backends&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;cudnn&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;benchmark&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;False&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;One line. That alone took a 4-second 240p clip from about 188 s to 86 s at 2x, and from 680 s to 270 s at 4x with sparse attention.&lt;/p&gt;

&lt;p&gt;There is a related MIOpen detail: its &lt;code&gt;Find&lt;/code&gt; mode runs for every new convolution shape unless &lt;code&gt;MIOPEN_FIND_MODE=FAST&lt;/code&gt; is set. Without it, the decoder's first call on a fresh process cost about 100 seconds. Set it in the worker environment.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Move the DiT off the card before decode
&lt;/h2&gt;

&lt;p&gt;At a large donor resolution, the KV cache for the diffusion transformer is roughly 7.5 GB. With the DiT resident on the GPU, the worker reserved about 15 GB of the 16 GB card. Add the desktop compositor and a browser tab, and Windows starts paging GPU memory. Individual decode steps stalled for 7-15 seconds while that shuffling happened.&lt;/p&gt;

&lt;p&gt;Offloading the DiT to host RAM just for the decode phase, then bringing it back for the next denoising pass, dropped decode from 53 s to 5 s per two chunks. End-to-end jobs got about 11% faster, with identical files.&lt;/p&gt;

&lt;p&gt;The rule I settled on: at a donor 1024 px wide or more, offload for decode. On smaller donors the transfer costs more than it saves. Steady-state steps run about 3.4 s; the first one or two still run near the memory edge, so this is not a free pass on VRAM planning.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Keep the warm worker alive
&lt;/h2&gt;

&lt;p&gt;This one is not ROCm-specific, but it was the biggest local win. The app used to restart the worker every two chunks because WSL reported about 10 GB of host RAM and the memory tuner treated that as a tiny machine. Every restart reloaded the model, which on this card is minutes.&lt;/p&gt;

&lt;p&gt;Two fixes: pass the real host RAM across from Windows (&lt;code&gt;PHOENIX_HOST_RAM_GB&lt;/code&gt;), and raise the warm-restart interval from 2 to 12 on a 24-40 GB host. Chunks also went from 1 s to 2 s of source video, which halves the number of temporal overlaps to reconcile. Expect roughly 1.5-2.5x wall-time improvement, not a miracle: dense attention on RDNA3 is still slow, around a minute per second of 320-360p source.&lt;/p&gt;

&lt;p&gt;One thing to watch: channels-last convolutions were 200-1000x slower on RDNA3. If a pipeline change quietly switches layout, a job that took minutes will take hours. Worth an assertion in CI.&lt;/p&gt;

&lt;h2&gt;
  
  
  A note on torch.compile
&lt;/h2&gt;

&lt;p&gt;I tried regional &lt;code&gt;torch.compile&lt;/code&gt; on the DiT blocks. Published numbers for gfx1100 are mostly breakage reports, not speedups: LLVM assertions and black output. That matched what I saw, so I left it off. If you try it, compile per block at fixed shapes and diff the output against eager before trusting it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Where this leaves things
&lt;/h2&gt;

&lt;p&gt;None of these change the picture. That was the constraint from the start: I'd rather ship a restore that takes an extra minute than one that quietly invents detail or introduces a halo around moving people. The quality rules are in the &lt;a href="https://phoenixlabs.space/upscaler-guide" rel="noopener noreferrer"&gt;Upscaler guide&lt;/a&gt;, and there is a longer write-up on &lt;a href="https://phoenixlabs.space/ai-video-upscaling-amd-gpu" rel="noopener noreferrer"&gt;AI upscaling on AMD GPUs&lt;/a&gt; with the hardware specifics.&lt;/p&gt;

&lt;p&gt;If you are profiling a similar pipeline on RDNA3, the cuDNN benchmark setting is the first thing I would check. It is the kind of default that is correct on CUDA and quietly expensive on ROCm.&lt;/p&gt;

</description>
      <category>performance</category>
    </item>
    <item>
      <title>We audited our own Android AI chat app. Here's everything that leaves the phone.</title>
      <dc:creator>Phoenix Labs</dc:creator>
      <pubDate>Tue, 17 Nov 2026 14:49:50 +0000</pubDate>
      <link>https://dev.to/thekillsquad007/we-audited-our-own-android-ai-chat-app-heres-everything-that-leaves-the-phone-4gb9</link>
      <guid>https://dev.to/thekillsquad007/we-audited-our-own-android-ai-chat-app-heres-everything-that-leaves-the-phone-4gb9</guid>
      <description>&lt;p&gt;We ship &lt;a href="https://phoenixlabs.space/local-ai" rel="noopener noreferrer"&gt;Phoenix Local AI&lt;/a&gt;, a private AI chat app for Android. Its whole pitch is that a model can run on the phone itself, in airplane mode, with nothing leaving the device.&lt;/p&gt;

&lt;p&gt;A pitch like that is easy to write and easy to disbelieve. So before we published the privacy page, we went through the app network call by network call and wrote down everything that leaves the phone. This is that list, plus the three cases where a connection is real and you asked for it.&lt;/p&gt;

&lt;h2&gt;
  
  
  The audit, in one paragraph
&lt;/h2&gt;

&lt;p&gt;The test was boring, which is the point. Fresh install, no server added, no cloud provider, no key pasted anywhere. Use the app for a week: chat with an on-device model, attach a photo, ask about a document, let a companion remember things, use voice mode, connect an MCP tool, kill the network entirely and keep chatting. Then look at what the app actually touched.&lt;/p&gt;

&lt;p&gt;Everything below is what we could reproduce, not what we hope happens.&lt;/p&gt;

&lt;h2&gt;
  
  
  What never leaves the phone
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Your chats.&lt;/strong&gt; They live in the app's storage on the phone. With an on-device model they are not sent anywhere, because there is nowhere to send them.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Companion memory.&lt;/strong&gt; When a companion "remembers" your dog's name or that interview on Friday, it is a list kept on the phone. It goes to the model you chat with, and that model never leaves the phone if it's an on-device one.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Backups.&lt;/strong&gt; The backup file is yours. It stays on the phone until you move it yourself, and restoring it on a new phone is a file copy, not a sync through us.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Personas, saved prompts, settings.&lt;/strong&gt; All local. Temporary chats are never stored at all.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;There is no account, no analytics SDK, no ads SDK. There is nothing to tie your chats to, because there is no account to tie them to.&lt;/p&gt;

&lt;h2&gt;
  
  
  The three connections, and only these three
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Model downloads from Hugging Face.&lt;/strong&gt; When you pick a model, it downloads once. After that it runs with no connection at all. You can see the list before you download, and you can bring any GGUF model yourself.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;A licence check with Lemon Squeezy, about once a week.&lt;/strong&gt; Being offline never locks you out. If the check fails, the app keeps working and retries later; it does not phone home per message.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Your own server, if you add one.&lt;/strong&gt; You can point the app at Ollama, LM Studio, any OpenAI-compatible server on your network, or OpenRouter/Requesty with your own key. Messages go straight from your phone to the server you chose. Never through us. If you never add one, this connection does not exist.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;That's the complete list. We published it on the site as &lt;a href="https://phoenixlabs.space/local-ai" rel="noopener noreferrer"&gt;"What leaves your phone"&lt;/a&gt; because a privacy page that says "we take privacy seriously" says nothing.&lt;/p&gt;

&lt;h2&gt;
  
  
  The checks that surprised us
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Airplane mode is the honest test.&lt;/strong&gt; After a model is downloaded, the app fully works in airplane mode. If any hidden beacon existed, this is where it would fail. It doesn't.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The licence check is weekly, not per-chat.&lt;/strong&gt; We expected per-message; the code says once a week, and a week offline confirmed it.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Native crashes hide from Flutter logs.&lt;/strong&gt; Not privacy, but adjacent: when we were testing, on-device model crashes only showed up in plain &lt;code&gt;adb logcat&lt;/code&gt;. If you audit an app like this, logcat is where the truth is.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Why we sell it this way
&lt;/h2&gt;

&lt;p&gt;The app is $9.99 once, with a 7-day trial where everything is unlocked and no card is needed. One key works on up to 3 phones. We sell directly so there is no store cut, no store account, and no store's idea of what your data is worth. New versions come from the same page you downloaded the APK from, and installing one over the old keeps your chats.&lt;/p&gt;

&lt;p&gt;If you are building anything that runs on a user's device, do this audit before your marketing copy does. The list of what leaves the device is usually short. Writing it down is what makes it honest.&lt;/p&gt;

&lt;h2&gt;
  
  
  The short version
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;What&lt;/th&gt;
&lt;th&gt;Where it goes&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Chats, memories, settings&lt;/td&gt;
&lt;td&gt;Nowhere. On the phone.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Model download&lt;/td&gt;
&lt;td&gt;Hugging Face, once, when you pick a model&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Licence check&lt;/td&gt;
&lt;td&gt;Lemon Squeezy, about once a week&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Messages to your own server&lt;/td&gt;
&lt;td&gt;Direct to the server you added, if you added one&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Analytics, ads, account&lt;/td&gt;
&lt;td&gt;Do not exist&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;On-device model plus no account plus no analytics means the only thing the app can leak is the thing you explicitly wired up yourself. That is the whole privacy story, and it is the one we will keep.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>android</category>
      <category>llm</category>
      <category>privacy</category>
    </item>
    <item>
      <title>Selling 59-cent AI video clips without inventing a currency (a wallet on Cloudflare D1)</title>
      <dc:creator>Phoenix Labs</dc:creator>
      <pubDate>Sat, 14 Nov 2026 05:22:40 +0000</pubDate>
      <link>https://dev.to/thekillsquad007/selling-59-cent-ai-video-clips-without-inventing-a-currency-a-wallet-on-cloudflare-d1-1ago</link>
      <guid>https://dev.to/thekillsquad007/selling-59-cent-ai-video-clips-without-inventing-a-currency-a-wallet-on-cloudflare-d1-1ago</guid>
      <description>&lt;p&gt;&lt;a href="https://phoenixlabs.space/motion" rel="noopener noreferrer"&gt;Phoenix Motion&lt;/a&gt; turns a still image into a five-second video with sound. A 480p clip costs $0.59.&lt;/p&gt;

&lt;p&gt;That price creates a payments problem. My payment provider, Lemon Squeezy, charges $0.50 plus 5% per transaction. Selling one $0.59 clip per checkout would hand most of it to fees, and nobody wants to go through a checkout for every clip anyway.&lt;/p&gt;

&lt;p&gt;The usual answer is credits: sell a "500 credit pack", price clips in credits, let credits expire. I don't like credits. They hide the real price, the packs never divide evenly, and expiring them is a polite way of keeping money for nothing. So the rules I set were:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The balance is &lt;strong&gt;US dollars, shown as dollars&lt;/strong&gt;. A clip costs $0.59, not "12 credits".&lt;/li&gt;
&lt;li&gt;You top up any amount from $5 to $200. No packs.&lt;/li&gt;
&lt;li&gt;It &lt;strong&gt;never expires&lt;/strong&gt;, and an unused balance is refundable on request.&lt;/li&gt;
&lt;li&gt;No account and no password.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here's how that works on Cloudflare Workers with a D1 (SQLite) database.&lt;/p&gt;

&lt;h2&gt;
  
  
  Identity without accounts
&lt;/h2&gt;

&lt;p&gt;When you first open the app, the browser generates a wallet key, a long random string with a &lt;code&gt;pmk_&lt;/code&gt; prefix. The server only stores its SHA-256 hash. Whoever holds the key holds the balance.&lt;/p&gt;

&lt;p&gt;The obvious problem: clear your browser and the balance is gone. The recovery path is the receipt email. Lemon Squeezy lets a checkout carry a custom receipt link, and the top-up puts the wallet key in that link's &lt;strong&gt;URL fragment&lt;/strong&gt; (&lt;code&gt;...#key=pmk_...&lt;/code&gt;). Fragments are never sent to a server, so the key doesn't land in anyone's access logs, but clicking the button in the receipt email opens the app with the key back in your browser. No login system, no email service of my own.&lt;/p&gt;

&lt;h2&gt;
  
  
  Every change is a ledger row
&lt;/h2&gt;

&lt;p&gt;The balance lives in a &lt;code&gt;wallets&lt;/code&gt; table, but nothing ever updates it on its own. Every change is a row in &lt;code&gt;wallet_ledger&lt;/code&gt; with a &lt;code&gt;kind&lt;/code&gt; (&lt;code&gt;topup&lt;/code&gt;, &lt;code&gt;hold&lt;/code&gt;, &lt;code&gt;release&lt;/code&gt;, &lt;code&gt;refund&lt;/code&gt;...) and a &lt;code&gt;ref&lt;/code&gt; (the order ID, the clip ID), and &lt;code&gt;(kind, ref)&lt;/code&gt; is unique.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;ledger&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;walletId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;delta&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;kind&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;ref&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;DB&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;batch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;
      &lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;DB&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;prepare&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="s2"&gt;"INSERT INTO wallet_ledger (wallet_id, delta_cents, kind, ref, created_at) VALUES (?,?,?,?,?)"&lt;/span&gt;
      &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;bind&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;walletId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;delta&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;kind&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;ref&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;nowIso&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="p"&gt;,&lt;/span&gt;
      &lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;DB&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;prepare&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="s2"&gt;"UPDATE wallets SET balance_cents = balance_cents + ?, updated_at = ? WHERE id = ?"&lt;/span&gt;
      &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;bind&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;delta&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;nowIso&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="n"&gt;walletId&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="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;e&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="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;String&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;includes&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"UNIQUE"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// already applied&lt;/span&gt;
    &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="n"&gt;e&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;D1's &lt;code&gt;batch()&lt;/code&gt; runs as a transaction, so the row and the balance change land together or not at all. The unique constraint makes it idempotent: if Lemon Squeezy delivers the same &lt;code&gt;order_created&lt;/code&gt; webhook three times, or a webhook and a polling check race each other, the second insert fails on &lt;code&gt;UNIQUE&lt;/code&gt; and the balance moves once. That's the whole defence against double credits and double refunds, and it's enforced by the database rather than by my code remembering to check.&lt;/p&gt;

&lt;h2&gt;
  
  
  The hard part: two tabs, one dollar
&lt;/h2&gt;

&lt;p&gt;Starting a clip holds its price. The naive version reads the balance, checks it's enough, then subtracts. Open two tabs with $0.60 left, start a clip in each at the same moment, and both reads see $0.60. Both clips start. The balance goes negative.&lt;/p&gt;

&lt;p&gt;The fix is to make the check and the write the same statement:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;row&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;DB&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;batch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;
  &lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;DB&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;prepare&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="sb"&gt;`INSERT INTO wallet_ledger (wallet_id, delta_cents, kind, ref, created_at)
     SELECT ?, ?, 'hold', ?, ? WHERE EXISTS
       (SELECT 1 FROM wallets WHERE id = ? AND locked = 0 AND balance_cents &amp;gt;= ?)`&lt;/span&gt;
  &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;bind&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;walletId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;cents&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;jobId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;nowIso&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="n"&gt;walletId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;cents&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;DB&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;prepare&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="sb"&gt;`UPDATE wallets SET balance_cents = balance_cents - ?, updated_at = ?
     WHERE id = ? AND EXISTS
       (SELECT 1 FROM wallet_ledger WHERE kind = 'hold' AND ref = ? AND wallet_id = ?)`&lt;/span&gt;
  &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;bind&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;cents&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;nowIso&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="n"&gt;walletId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;jobId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;walletId&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="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nb"&gt;Boolean&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;row&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;meta&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;changes&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The ledger row is only written if the balance covers the price, and the balance only moves if that row exists. Inside one transaction, the second tab's insert sees the first tab's deduction and writes nothing. &lt;code&gt;meta.changes&lt;/code&gt; tells the caller whether the hold happened. No locks, no read-then-write gap.&lt;/p&gt;

&lt;p&gt;When a clip finishes, the hold is kept. When it fails, is refused by the content check, or is cancelled, a &lt;code&gt;release&lt;/code&gt; row with the same &lt;code&gt;ref&lt;/code&gt; gives it back, and the same unique constraint means it can only be given back once.&lt;/p&gt;

&lt;h2&gt;
  
  
  Refunds go back through the ledger too
&lt;/h2&gt;

&lt;p&gt;A Lemon Squeezy refund arrives as an &lt;code&gt;order_refunded&lt;/code&gt; webhook, possibly partial. It's another ledger row, negative this time, keyed on the refund. Top-ups are checked against what was actually paid (&lt;code&gt;subtotal_usd&lt;/code&gt;, with 2% slack for currency rounding), so an underpayment doesn't credit the full amount.&lt;/p&gt;

&lt;p&gt;A webhook that never arrives is the failure you don't see, so a scheduled job compares Lemon Squeezy's recent orders against the ledger and emails me when an order was paid but never credited, or refunded but never debited.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I tested before it took real money
&lt;/h2&gt;

&lt;p&gt;All of this ran locally on &lt;code&gt;wrangler dev&lt;/code&gt; first: create a wallet, top up, hold, release on failure, release twice (second one must do nothing), one wallet trying to read another's clips, a bad webhook signature, a duplicate webhook, a partial then a full refund, an underpayment, and a test-mode webhook hitting live mode. Every one of those is a way real money goes wrong.&lt;/p&gt;

&lt;h2&gt;
  
  
  The result
&lt;/h2&gt;

&lt;p&gt;You top up once, every clip comes off a balance shown in dollars, and the price on the page is the price you pay. The same balance now also pays for AI agents using Phoenix through its MCP server, each with its own spending limit, and it can be topped up in USDC as well as by card. The ledger didn't need to change for either.&lt;/p&gt;

&lt;p&gt;If you want to see it from the customer's side, &lt;a href="https://phoenixlabs.space/motion" rel="noopener noreferrer"&gt;Phoenix Motion&lt;/a&gt; is live, and every example clip on the page is a first take, sound included. And if you're running image-to-video on your own hardware instead, I wrote up &lt;a href="https://phoenixlabs.space/wan-2-2-8gb-gpu" rel="noopener noreferrer"&gt;how we fit Wan 2.2's 14B model on an 8 GB GPU&lt;/a&gt;, Radeons included.&lt;/p&gt;

</description>
      <category>cloudflare</category>
      <category>webdev</category>
      <category>sql</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Running Qwen 3 on a five-year-old Android phone with LiteRT-LM (what I measured)</title>
      <dc:creator>Phoenix Labs</dc:creator>
      <pubDate>Sat, 14 Nov 2026 05:21:33 +0000</pubDate>
      <link>https://dev.to/thekillsquad007/running-qwen-3-on-a-five-year-old-android-phone-with-litert-lm-what-i-measured-3mo4</link>
      <guid>https://dev.to/thekillsquad007/running-qwen-3-on-a-five-year-old-android-phone-with-litert-lm-what-i-measured-3mo4</guid>
      <description>&lt;p&gt;I ship &lt;a href="https://phoenixlabs.space/local-ai" rel="noopener noreferrer"&gt;Phoenix Local AI&lt;/a&gt;, a private AI chat app for Android. You can connect it to a cloud model, but the point is that it can run a model on the phone itself, in airplane mode, with nothing leaving the device.&lt;/p&gt;

&lt;p&gt;The on-device engine is &lt;a href="https://github.com/google-ai-edge/LiteRT-LM" rel="noopener noreferrer"&gt;LiteRT-LM&lt;/a&gt;, Google's runtime for &lt;code&gt;.litertlm&lt;/code&gt; model files, called from Flutter. Getting it to answer at all was one job. Getting it to answer at a speed a person will wait for, on a phone that isn't a flagship, was another. These are my notes, measured on a POCO M2 Pro from 2020 over wireless adb, because a phone like that is a better test of "runs on a phone" than whatever's new this year.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Pin the runtime, and pin the models
&lt;/h2&gt;

&lt;p&gt;The Flutter plugin I started from bundled a LiteRT-LM build, and the version matters more than you'd expect:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;0.18&lt;/strong&gt; worked with my bindings.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;0.19&lt;/strong&gt; is labelled "C API 1.0" and breaks the ABI. Nothing warns you; it just stops working.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So the app pins 0.18. That has a knock-on effect on models: on 0.18, older &lt;code&gt;.litertlm&lt;/code&gt; files with pre-0.18 chat templates either fail or silently drop the user's turn, and files that keep weights outside the graph crash the GPU backend (&lt;a href="https://github.com/google-ai-edge/LiteRT-LM/issues/3986" rel="noopener noreferrer"&gt;LiteRT-LM#3986&lt;/a&gt;). The litert-community repos on Hugging Face update files in place, so "Qwen3-0.6B" today isn't the file I tested. I pin each model to a specific repo revision.&lt;/p&gt;

&lt;p&gt;If your on-device model works on one install and not another, check the runtime version and the exact model revision before you check your code.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. CPU decode didn't move. At all.
&lt;/h2&gt;

&lt;p&gt;I expected to tune the CPU path. Thread count, fp16 versus fp32 activations, KV cache size, a smaller model. On 0.18, on this phone, decode speed sat at about &lt;strong&gt;2.8 tokens a second&lt;/strong&gt; regardless of every one of them, including model size. Trying the YNNPACK backend returned UNIMPLEMENTED, so there was no faster CPU path to switch to either.&lt;/p&gt;

&lt;p&gt;When every knob gives the same number, you're not limited by the thing you're turning. I stopped turning.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. The GPU is the actual fix
&lt;/h2&gt;

&lt;p&gt;On the GPU backend, Qwen 3 0.6B ran at about &lt;strong&gt;6.6 tokens a second&lt;/strong&gt;, with the first words on screen in about &lt;strong&gt;3 seconds&lt;/strong&gt;. That's the difference between "is it broken?" and "it's typing".&lt;/p&gt;

&lt;p&gt;So the Qwen 3 entries in the app's model list carry a "prefers GPU" flag. The GPU path isn't safe everywhere, so the app keeps a CPU fallback: it writes a crash marker before starting the GPU backend and clears it once the model is up. If the app dies in between, the next launch sees the marker and uses the CPU for that model instead of crashing in a loop.&lt;/p&gt;

&lt;p&gt;A practical note: native crashes from LiteRT-LM don't show up in Flutter's logs. They're in plain &lt;code&gt;adb logcat&lt;/code&gt; under the tag &lt;code&gt;native&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Qwen 3 thinks unless you tell it not to
&lt;/h2&gt;

&lt;p&gt;Qwen 3 is a hybrid reasoning model and thinks by default: before answering, it writes a block of reasoning. On a server that's free. At 6.6 tokens a second on a phone, a few hundred tokens of thinking is a long, silent pause before the answer starts.&lt;/p&gt;

&lt;p&gt;The fix is to pass &lt;code&gt;enable_thinking&lt;/code&gt; explicitly on every request, true or false, rather than relying on a default. The app turns it off for normal chat.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. x86 emulators can't test this
&lt;/h2&gt;

&lt;p&gt;Curated &lt;code&gt;.litertlm&lt;/code&gt; models refuse to load on an x86_64 emulator ("require arm64-v8a"). That's by design, not a bug. For emulator tests I imported a small GGUF model, which runs through the llama.cpp path, and kept the LiteRT-LM testing on a real arm64 phone.&lt;/p&gt;

&lt;h2&gt;
  
  
  Small models, small jobs
&lt;/h2&gt;

&lt;p&gt;A 0.6B to 1.7B model on a phone is not a frontier model, and I didn't want the app to pretend otherwise. I looked at building a coding-agent mode and dropped it: small models are weak at multi-step tool use, and a phone is a bad place to discover that. What they're good at is conversation, so the app leans that way, including a few characters with short memories stored on the phone. The memory works with plain &lt;code&gt;[remember: ...]&lt;/code&gt; tags the model writes in its reply. It's simple and it works at this size.&lt;/p&gt;

&lt;h2&gt;
  
  
  Numbers in one place
&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;&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Phone&lt;/td&gt;
&lt;td&gt;POCO M2 Pro (2020), arm64&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Runtime&lt;/td&gt;
&lt;td&gt;LiteRT-LM 0.18, pinned&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;CPU decode&lt;/td&gt;
&lt;td&gt;~2.8 tok/s, unchanged by threads, precision, KV size or model size&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;GPU decode, Qwen 3 0.6B&lt;/td&gt;
&lt;td&gt;~6.6 tok/s, first words in ~3 s&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Must set&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;enable_thinking&lt;/code&gt; on every request&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;a href="https://phoenixlabs.space/local-ai" rel="noopener noreferrer"&gt;Phoenix Local AI&lt;/a&gt; is $9.99 once, with a 7-day trial and no account. The APK is on GitHub rather than the Play Store for now. If you're building on LiteRT-LM and hit something I didn't, I'd like to hear it.&lt;/p&gt;

</description>
      <category>android</category>
      <category>flutter</category>
      <category>ai</category>
      <category>machinelearning</category>
    </item>
    <item>
      <title>I measured my auto video editor on real streams. It was picking the outro.</title>
      <dc:creator>Phoenix Labs</dc:creator>
      <pubDate>Sat, 14 Nov 2026 05:20:30 +0000</pubDate>
      <link>https://dev.to/thekillsquad007/i-measured-my-auto-video-editor-on-real-streams-it-was-picking-the-outro-77d</link>
      <guid>https://dev.to/thekillsquad007/i-measured-my-auto-video-editor-on-real-streams-it-was-picking-the-outro-77d</guid>
      <description>&lt;p&gt;I build &lt;a href="https://phoenixlabs.space/editor" rel="noopener noreferrer"&gt;Phoenix Editor&lt;/a&gt;, a desktop app that takes a long stream or Let's Play recording, cuts the dead air and filler words, and turns the best moments into captioned vertical Shorts. It runs on your own GPU: faster-whisper on NVIDIA, whisper.cpp over Vulkan on AMD and Intel, and the encoder your card has.&lt;/p&gt;

&lt;p&gt;For months the test suite ran it against generated fixtures, and everything passed. Then someone called it "vibecoded slop" in public, and I realised I had no evidence they were wrong. Nothing in the repo showed the edits were actually good on real footage.&lt;/p&gt;

&lt;p&gt;So I built a harness, ran it on real commentary, and wrote down what came back. This post is the numbers, the bugs they exposed, and the fixes.&lt;/p&gt;

&lt;h2&gt;
  
  
  The harness
&lt;/h2&gt;

&lt;p&gt;Scoring an edit is harder than it sounds, because "good" is subjective. I picked things I could measure:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Words lost.&lt;/strong&gt; Transcribe the source with a separate model (Whisper &lt;code&gt;medium.en&lt;/code&gt;, word timestamps). Any reference word that falls inside a removed range was cut by mistake.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Words clipped.&lt;/strong&gt; A cut boundary that lands inside a word, so the edit says "basi-" and jumps.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Fillers removed.&lt;/strong&gt; Reference "um"s and "uh"s that are actually gone from the render.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;What the Shorts picker chose&lt;/strong&gt;, checked by watching them.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The test set was CC-BY and CC-BY-SA videos from archive.org and similar, uploaded by the people who made them:&lt;/p&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;Length&lt;/th&gt;
&lt;th&gt;Kind&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;A raw Twitch stream&lt;/td&gt;
&lt;td&gt;3h 09m&lt;/td&gt;
&lt;td&gt;VTuber overlay, horror RPG&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;An FPS first-impressions video&lt;/td&gt;
&lt;td&gt;20m&lt;/td&gt;
&lt;td&gt;facecam, lightly edited&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;A two-player strategy game&lt;/td&gt;
&lt;td&gt;11m&lt;/td&gt;
&lt;td&gt;two voices&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Two Let's Play episodes&lt;/td&gt;
&lt;td&gt;50m each&lt;/td&gt;
&lt;td&gt;no commentary at all&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The two with no commentary were a free check: the engine should refuse them rather than "edit" a silent video. It did.&lt;/p&gt;

&lt;h2&gt;
  
  
  Round one
&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;3h stream&lt;/th&gt;
&lt;th&gt;FPS&lt;/th&gt;
&lt;th&gt;strategy&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Removed&lt;/td&gt;
&lt;td&gt;63 of 189 min&lt;/td&gt;
&lt;td&gt;5.7 of 20 min&lt;/td&gt;
&lt;td&gt;2.3 of 11 min&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Reference words lost&lt;/td&gt;
&lt;td&gt;4.1%&lt;/td&gt;
&lt;td&gt;1.8%&lt;/td&gt;
&lt;td&gt;2.5%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Words with a cut inside them&lt;/td&gt;
&lt;td&gt;2.6%&lt;/td&gt;
&lt;td&gt;1.7%&lt;/td&gt;
&lt;td&gt;2.4%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Fillers removed&lt;/td&gt;
&lt;td&gt;2 of 19&lt;/td&gt;
&lt;td&gt;2 of 36&lt;/td&gt;
&lt;td&gt;3 of 8&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Losing one word in 25 sounds small until you watch it. Every lost word came from a silence cut. About 60% sat within 0.4 s of a cut edge, so the padding was too tight. The rest were deep inside a "silence" that wasn't: quiet speech under game audio.&lt;/p&gt;

&lt;p&gt;The fillers were worse, and the cause was not my code. &lt;strong&gt;Whisper doesn't write "um" and "uh" by default.&lt;/strong&gt; It cleans them out of the transcript, and a filler detector that reads the transcript can't cut what isn't there.&lt;/p&gt;

&lt;p&gt;And the Shorts were bad enough to be funny:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;On the 3-hour stream, all five Shorts came from the first eight minutes: pre-game chat about having a cold. None from the two boss fights the stream was named after.&lt;/li&gt;
&lt;li&gt;On the FPS video, three of five were the outro.&lt;/li&gt;
&lt;li&gt;On the strategy video, the intro and the outro.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Why the Shorts picker failed
&lt;/h2&gt;

&lt;p&gt;The first version scored fixed 15-second windows on a 5-second grid by loudness and words per second. That rewards exactly the wrong thing. When does a streamer talk fast and loud? When they're explaining something to the camera: the intro, the outro, the sponsor bit. When something actually happens in the game, they react: "oh", "no no no", "wait", "let's go". Short bursts, not monologue.&lt;/p&gt;

&lt;p&gt;And a grid window starts and ends wherever the grid says, which is mid-sentence.&lt;/p&gt;

&lt;h2&gt;
  
  
  The fixes
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Cut edges.&lt;/strong&gt; Silence cuts now stop short of every transcribed word: 80 ms before it, 120 ms after. One subtle bug on the way: there's a cap on how long a silence cut can be, and it was judged &lt;em&gt;after&lt;/em&gt; carving out words. A quiet half hour with one word in it got chopped into dozens of jump cuts, removing 504 s instead of 171. The cap is now judged on the whole pause first.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Fillers.&lt;/strong&gt; Whisper can be told to write them: hotwords on faster-whisper, an initial prompt on whisper.cpp. That worked, with a catch: primed to hear "uh", it also hears some short real words as "uh". Measured against the reference transcript, the culprits were the low-confidence ones and the implausibly long ones (a 3-second "uh" is a stretched timestamp over real speech). So a filler is only cut when Whisper is at least 40% sure and it's at most 1.2 s long. Leaving an "um" in is cheaper than cutting a word.&lt;/p&gt;

&lt;p&gt;There was a second filler bug, and it's my favourite: the fillers that &lt;em&gt;were&lt;/em&gt; detected mostly never left the render. The pause padding, scene snapping and word guards that protect speech were also erasing the tiny filler cuts. Only 6 of 27 detected fillers made it out. Filler cuts now skip those steps and keep a 40 ms margin.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Repetition loops.&lt;/strong&gt; Turning on hotwords together with conditioning on previous text locked faster-whisper into repeating one line from minute 70 of the 3-hour stream to the end: 386 words where there should have been about 1,500. Conditioning is off now, and both backends collapse runs of four or more identical sentences.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Shorts, rebuilt:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Clips are built from whole sentences, 20 to 45 seconds, so a Short opens on a thought and closes on one.&lt;/li&gt;
&lt;li&gt;The main signal is reaction density, not talk. Loudness and speech rate only count relative to the speaker's own level a few minutes either side, so someone who is loud all night doesn't win everywhere.&lt;/li&gt;
&lt;li&gt;A vision pass labels scenes. Combat and cutscenes add to a clip; menus, loading screens and idle subtract.&lt;/li&gt;
&lt;li&gt;Intros, outros and "links in the description" are ruled out, and the first and last couple of minutes of a long recording are discounted.&lt;/li&gt;
&lt;li&gt;Picks are spread out, with a minimum gap that scales with the recording's length. And if there aren't five good moments, you get fewer Shorts rather than filler.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The layout changed too. On a facecam recording, the old reframer followed the face, so the 9:16 crop was the webcam corner and the gameplay was cropped away. Now the facecam is found (YuNet plus edge refinement) and stacked above the gameplay, with 2 to 3 word captions at the seam.&lt;/p&gt;

&lt;h2&gt;
  
  
  Round two
&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;FPS before&lt;/th&gt;
&lt;th&gt;FPS after&lt;/th&gt;
&lt;th&gt;strategy before&lt;/th&gt;
&lt;th&gt;strategy after&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Reference words lost&lt;/td&gt;
&lt;td&gt;1.8%&lt;/td&gt;
&lt;td&gt;0.99%&lt;/td&gt;
&lt;td&gt;2.5%&lt;/td&gt;
&lt;td&gt;0.22%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Words with a cut inside them&lt;/td&gt;
&lt;td&gt;1.7%&lt;/td&gt;
&lt;td&gt;1.36%&lt;/td&gt;
&lt;td&gt;2.4%&lt;/td&gt;
&lt;td&gt;1.25%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Fillers removed from the render&lt;/td&gt;
&lt;td&gt;~2&lt;/td&gt;
&lt;td&gt;20 of 27 detected&lt;/td&gt;
&lt;td&gt;~3&lt;/td&gt;
&lt;td&gt;3 of 5 detected&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The Shorts on the FPS video are now five gameplay reactions ("whoa whoa whoa", "it feels like a war zone", "just ate a grenade"). The strategy video gets four mid-game moments.&lt;/p&gt;

&lt;h2&gt;
  
  
  What's still weak
&lt;/h2&gt;

&lt;p&gt;The raw 3-hour VTuber stream. The avatar has no face to stack, the vision pass mislabels an intermission card as gameplay, and some of the transcribed speech is game dialogue rather than the streamer. Those picks are still poor, and I'd rather say so than pretend.&lt;/p&gt;

&lt;p&gt;The filler confidence gate also only works on the NVIDIA path for now, because whisper.cpp's per-word confidence isn't wired in yet.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I'd tell anyone building something similar
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Test on real footage early.&lt;/strong&gt; Generated fixtures tested that the code ran. They couldn't tell me it picked the outro.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Score against an independent transcript.&lt;/strong&gt; If you score your edit with the same transcript you used to make it, every mistake is invisible.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Whisper's defaults are tuned for clean text, not editing.&lt;/strong&gt; If you need disfluencies, ask for them, then filter what comes back.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;"Loud and fast" is not "exciting".&lt;/strong&gt; Reactions are.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Phoenix Editor runs on Windows and Linux, on AMD or NVIDIA, and nothing uploads. There's a &lt;a href="https://phoenixlabs.space/editor" rel="noopener noreferrer"&gt;7-day free trial&lt;/a&gt; with every feature and no watermark, and a &lt;a href="https://phoenixlabs.space/editor-guide" rel="noopener noreferrer"&gt;setup guide&lt;/a&gt; if you want to throw a VOD at it. If it picks your outro, tell me.&lt;/p&gt;

</description>
      <category>python</category>
      <category>ai</category>
      <category>opensource</category>
      <category>programming</category>
    </item>
    <item>
      <title>Why upscaling old low-res video makes it look worse, and the ffmpeg filters that fix it</title>
      <dc:creator>Phoenix Labs</dc:creator>
      <pubDate>Thu, 05 Nov 2026 10:38:08 +0000</pubDate>
      <link>https://dev.to/thekillsquad007/why-upscaling-old-low-res-video-makes-it-look-worse-and-the-ffmpeg-filters-that-fix-it-4nnf</link>
      <guid>https://dev.to/thekillsquad007/why-upscaling-old-low-res-video-makes-it-look-worse-and-the-ffmpeg-filters-that-fix-it-4nnf</guid>
      <description>&lt;p&gt;If you've ever run an old 240p YouTube rip or a 2012 phone video through an AI upscaler, you've probably seen this: the output is bigger and sharper, and somehow looks &lt;em&gt;worse&lt;/em&gt;. Faces turn into mosaics. Flat walls grow a grid of tiles. Edges get a crunchy halo.&lt;/p&gt;

&lt;p&gt;I build a video restoration app, and this was one of the first quality bugs I had to understand properly. The short version: the upscaler is doing its job. It's sharpening exactly what you gave it, and what you gave it was mostly compression damage.&lt;/p&gt;

&lt;p&gt;This post covers what that damage is, how to tell which kind your clip has, and the ffmpeg filters I run &lt;em&gt;before&lt;/em&gt; any upscaler touches the video.&lt;/p&gt;

&lt;h2&gt;
  
  
  Two kinds of old video, two different problems
&lt;/h2&gt;

&lt;p&gt;Most "old video" falls into one of two buckets, and they need opposite treatment.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tape and DVD (480i / 576i).&lt;/strong&gt; VHS, Hi8, MiniDV captures and DVDs are usually &lt;em&gt;interlaced&lt;/em&gt;: each frame is two half-pictures (fields) captured a fraction of a second apart. On motion you get the comb pattern, thin horizontal stripes on anything moving. There's also analog noise: chroma smear, grain, tracking wobble.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Low-res internet and phone video (≤ 288p, sometimes 360p and 480p).&lt;/strong&gt; Old uploads, early phone cameras, clips that have been re-shared five times. These are usually &lt;em&gt;progressive&lt;/em&gt;, so there's nothing to deinterlace, but they're crushed by compression. The encoder split each frame into 8×8 (or larger) blocks and threw away most of the detail inside each one. What's left is a picture made of tiles.&lt;/p&gt;

&lt;p&gt;The mistake I made at first was treating both the same way: a light deinterlace and a gentle denoise, then upscale. On tape that's fine. On a 240p download it's a disaster.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why the blocks get worse
&lt;/h2&gt;

&lt;p&gt;A neural upscaler is trained to find edges and texture and make them crisp. A block boundary &lt;em&gt;is&lt;/em&gt; an edge as far as the model is concerned: a hard, straight, high-contrast line. So it sharpens it.&lt;/p&gt;

&lt;p&gt;Upscale a 320×240 clip 4× and every 8×8 block becomes a 32×32 tile with a crisp outline. A gentle tape denoise doesn't help, because it's tuned for random grain and leaves the block grid alone.&lt;/p&gt;

&lt;p&gt;You can't fix this afterwards. Once the upscaler has decided the grid is real detail, it's baked into every frame. The fix has to happen before upscaling, while the blocks are still small.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 1: find out what you have
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;ffprobe&lt;/code&gt; tells you most of what you need:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ffprobe -v error -select_streams v:0 \
  -show_entries &lt;span class="nv"&gt;stream&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;width,height,field_order,codec_name,bit_rate \
  -of &lt;span class="nv"&gt;default&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;nw&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;1 input.mp4
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Roughly:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;field_order&lt;/code&gt; is &lt;code&gt;tt&lt;/code&gt;, &lt;code&gt;bb&lt;/code&gt;, &lt;code&gt;tb&lt;/code&gt; or &lt;code&gt;bt&lt;/code&gt; → interlaced. Treat it as tape.&lt;/li&gt;
&lt;li&gt;Height is 480, 486 or 576 with no field order reported → probably a tape or DVD capture that lost its metadata. Check a frame with motion for combing.&lt;/li&gt;
&lt;li&gt;Height is 288 or less → assume compression blocks, even if it looks "fine" at its native size.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That last rule is the one that matters. At 240p on a phone screen the blocks are barely visible. At 1080p they're the whole picture.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 2a: the tape path (deinterlace + light denoise)
&lt;/h2&gt;

&lt;p&gt;For interlaced sources:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ffmpeg -i tape.mp4 \
  -vf &lt;span class="s2"&gt;"yadif=0:-1:0,hqdn3d=2.0:1.5:3.0:2.5"&lt;/span&gt; \
  -c:v libx264 -crf 12 -preset fast -c:a copy \
  tape_clean.mp4
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;yadif=0:-1:0&lt;/code&gt; deinterlaces to one frame per frame, auto-detects field order, and processes every frame. If you want smoother motion and can afford double the frames, &lt;code&gt;yadif=1&lt;/code&gt; (or &lt;code&gt;bwdif=1&lt;/code&gt;) outputs one frame per &lt;em&gt;field&lt;/em&gt; instead.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;hqdn3d=2.0:1.5:3.0:2.5&lt;/code&gt; is a mild spatial + temporal denoise. The temporal part (the last two numbers) does most of the work on tape grain, because grain changes every frame and the picture doesn't.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Keep the denoise mild. Tape footage that has been denoised hard looks waxy, and an upscaler will happily sharpen wax.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 2b: the low-res path (deblock first)
&lt;/h2&gt;

&lt;p&gt;For ≤ 288p progressive sources:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ffmpeg -i lowres.mp4 \
  -vf &lt;span class="s2"&gt;"spp=5,deblock=filter=strong:block=8,hqdn3d=3.2:2.4:5.5:4.0"&lt;/span&gt; \
  -c:v libx264 -crf 12 -preset fast -c:a copy \
  lowres_clean.mp4
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Three filters, in this order:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;spp=5&lt;/code&gt;&lt;/strong&gt;, simple post-processing. It re-runs the DCT at shifted positions and averages the results, which is very good at removing block artifacts and ringing without blurring real edges much. Quality 5 is slow but worth it at these resolutions; the frames are tiny anyway.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;deblock=filter=strong:block=8&lt;/code&gt;&lt;/strong&gt; smooths what's left along the 8×8 grid specifically.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;hqdn3d&lt;/code&gt; with stronger settings&lt;/strong&gt; than the tape path, to clean up the mosquito noise around edges that both of the above leave behind.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Notice there's no &lt;code&gt;yadif&lt;/code&gt;. These clips are progressive, and deinterlacing a progressive source just throws away vertical resolution you can't spare.&lt;/p&gt;

&lt;p&gt;The result will look &lt;em&gt;softer&lt;/em&gt; than the original at native size. That's expected and it's the point: you've removed fake detail (the grid) so the upscaler can work on real detail.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 3: keep intermediates lossless
&lt;/h2&gt;

&lt;p&gt;This one cost me more than I'd like to admit. If your pipeline extracts frames, processes them and re-encodes, possibly several times, don't use JPEG for the intermediate frames.&lt;/p&gt;

&lt;p&gt;I had frames passing between stages as JPEG to save disk space. Every stage re-compressed them, adding a fresh layer of 8×8 blocks, and the sharpening at the end then brought all of those blocks out. I'd carefully deblocked the source and then put the blocks back myself.&lt;/p&gt;

&lt;p&gt;Use PNG. You don't need maximum compression; PNG at level 1 is fast and still lossless:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ffmpeg -i lowres_clean.mp4 -compression_level 1 frames/%06d.png
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Same idea for the intermediate &lt;em&gt;video&lt;/em&gt; files: &lt;code&gt;-crf 12&lt;/code&gt; (or lower) on the pre-clean output, as above, so you're not adding a new generation of compression before the upscaler sees it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 4: don't throw away pixels to save memory
&lt;/h2&gt;

&lt;p&gt;If you use a heavy model (a diffusion upscaler, for example) on a small GPU, it's tempting to downscale the input a bit more so it fits. Don't do this with a source that's already tiny.&lt;/p&gt;

&lt;p&gt;I had a memory fallback that dropped a 320-wide clip to 256 wide before inference. On paper that's a 20% cut. In practice, a 320×240 clip inferred at 256×192 and then stretched to 1080p is about a 5.6× stretch, and it looked pixelated no matter what came after. Shorter processing chunks at the native width were the better trade: slower, but the detail you start with is all the detail you'll ever have.&lt;/p&gt;

&lt;h2&gt;
  
  
  What to expect
&lt;/h2&gt;

&lt;p&gt;With the right pre-clean, a 240p clip upscaled to 1080p looks like a soft but &lt;em&gt;clean&lt;/em&gt; video: real faces instead of mosaics, flat walls that are actually flat. It won't look like it was shot in HD, and nothing honest will make it look that way. The goal is "the best version of what was recorded," not new detail invented by a model.&lt;/p&gt;

&lt;p&gt;Tape footage, deinterlaced and lightly denoised, usually scales much better, because a 480i capture has more real information in it than its resolution suggests.&lt;/p&gt;

&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Check &lt;code&gt;field_order&lt;/code&gt; and height with &lt;code&gt;ffprobe&lt;/code&gt; before choosing filters.&lt;/li&gt;
&lt;li&gt;Interlaced tape/DVD: &lt;code&gt;yadif&lt;/code&gt; + mild &lt;code&gt;hqdn3d&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;≤ 288p internet/phone video: &lt;code&gt;spp&lt;/code&gt; + &lt;code&gt;deblock&lt;/code&gt; + stronger &lt;code&gt;hqdn3d&lt;/code&gt;, and no deinterlacing.&lt;/li&gt;
&lt;li&gt;Deblock &lt;em&gt;before&lt;/em&gt; upscaling. You can't remove a grid the upscaler has already sharpened.&lt;/li&gt;
&lt;li&gt;Lossless intermediates (PNG, low CRF). Every JPEG generation adds blocks back.&lt;/li&gt;
&lt;li&gt;Don't downscale an already-tiny source to save memory.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;I use all of this in &lt;a href="https://phoenixlabs.space/upscaler" rel="noopener noreferrer"&gt;Phoenix Upscaler&lt;/a&gt;, a desktop app that picks the right path for each clip automatically. I wrote more about the two common cases on the site: &lt;a href="https://phoenixlabs.space/old-phone-video" rel="noopener noreferrer"&gt;restoring old phone video&lt;/a&gt; and &lt;a href="https://phoenixlabs.space/vhs-restoration-software" rel="noopener noreferrer"&gt;VHS restoration&lt;/a&gt;, and a step-by-step &lt;a href="https://phoenixlabs.space/upscale-low-resolution-video" rel="noopener noreferrer"&gt;upscaling 240p video&lt;/a&gt; guide. But the ffmpeg commands above work on their own, in front of any upscaler you like. If you are weighing up a paid tool, I put together an &lt;a href="https://phoenixlabs.space/topaz-video-ai-alternative" rel="noopener noreferrer"&gt;honest comparison with Topaz Video AI&lt;/a&gt; and why we sell Phoenix once instead of by subscription.&lt;/p&gt;

&lt;p&gt;If you've found filter settings that work better on a particular kind of source (Hi8, early-2000s webcam, 3GP phone video), I'd like to hear about them in the comments.&lt;/p&gt;

</description>
      <category>ffmpeg</category>
      <category>python</category>
      <category>ai</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Running FlashVSR on an AMD GPU with ROCm (and what broke along the way)</title>
      <dc:creator>Phoenix Labs</dc:creator>
      <pubDate>Thu, 05 Nov 2026 08:10:20 +0000</pubDate>
      <link>https://dev.to/thekillsquad007/running-flashvsr-on-an-amd-gpu-with-rocm-and-what-broke-along-the-way-5bnm</link>
      <guid>https://dev.to/thekillsquad007/running-flashvsr-on-an-amd-gpu-with-rocm-and-what-broke-along-the-way-5bnm</guid>
      <description>&lt;p&gt;FlashVSR is one of the more interesting video super-resolution models right now. It's a one-step diffusion model built on Wan 2.1, it streams long videos in chunks, and on an NVIDIA card it's fast enough to be practical. I used the &lt;a href="https://github.com/LujiaJin/FlashVSR-Pro" rel="noopener noreferrer"&gt;FlashVSR-Pro&lt;/a&gt; fork, which wraps it in a usable &lt;code&gt;infer.py&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;It also has a hard dependency on &lt;a href="https://github.com/mit-han-lab/Block-Sparse-Attention" rel="noopener noreferrer"&gt;Block-Sparse-Attention&lt;/a&gt;, a CUDA extension. No CUDA, no attention kernel, no model.&lt;/p&gt;

&lt;p&gt;I build a video restoration app that has to work on AMD cards too, so I spent a good chunk of August getting FlashVSR running on a Radeon RX 7800 XT (16 GB, RDNA3, gfx1101). It works now. This post is everything I had to change, in the order I hit it, so you don't have to rediscover it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Setup that finally worked:&lt;/strong&gt;&lt;/p&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;&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;GPU&lt;/td&gt;
&lt;td&gt;RX 7800 XT, 16 GB&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Host&lt;/td&gt;
&lt;td&gt;Windows 11 + WSL2, Ubuntu 24.04&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;ROCm&lt;/td&gt;
&lt;td&gt;7.2 system install inside WSL&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;PyTorch&lt;/td&gt;
&lt;td&gt;2.10.0+rocm7.0&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Precision&lt;/td&gt;
&lt;td&gt;fp16&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  1. Use WSL2, not native Windows
&lt;/h2&gt;

&lt;p&gt;AMD now ships preview PyTorch wheels for Windows, and they import fine. &lt;code&gt;torch.cuda.is_available()&lt;/code&gt; returns &lt;code&gt;True&lt;/code&gt;, your card shows up, and you feel great for about six seconds, which is roughly how long a full FlashVSR inference ran before it segfaulted. AMD's own notes mention intermittent crashes during inference on Windows, and that matched what I saw.&lt;/p&gt;

&lt;p&gt;The same card inside WSL2 was stable, and a lot faster: a plain fp16 matmul benchmark gave me about 50 TFLOP/s in WSL against about 16 on native Windows.&lt;/p&gt;

&lt;p&gt;Getting the GPU visible inside WSL took a few environment variables:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="kd"&gt;export&lt;/span&gt; &lt;span class="nv"&gt;HSA_ENABLE_DXG_DETECTION&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;1
&lt;span class="kd"&gt;export&lt;/span&gt; &lt;span class="nv"&gt;ROCM_PATH&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;/opt/rocm-7.2.0
&lt;span class="kd"&gt;export&lt;/span&gt; &lt;span class="nv"&gt;LD_LIBRARY_PATH&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;/opt/rocm-7.2.0/lib:&lt;span class="nv"&gt;$LD_LIBRARY_PATH&lt;/span&gt;
&lt;span class="kd"&gt;export&lt;/span&gt; &lt;span class="nv"&gt;HSA_OVERRIDE_GFX_VERSION&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;11.0.1   &lt;span class="c"&gt;# gfx1101; adjust for your card&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;One non-obvious fix: the PyTorch ROCm wheel bundles its own &lt;code&gt;libhsa-runtime64.so&lt;/code&gt;, and that copy didn't detect the GPU through WSL's DXG layer for me. Replacing it with the system ROCm copy (keep a backup) fixed it. If &lt;code&gt;rocminfo&lt;/code&gt; sees your card but PyTorch doesn't, check this first.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Make Block-Sparse-Attention optional
&lt;/h2&gt;

&lt;p&gt;FlashVSR imports the kernel at the top of &lt;code&gt;diffsynth/models/wan_video_dit.py&lt;/code&gt;. Step one is letting it fail:&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="k"&gt;try&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;block_sparse_attn&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;block_sparse_attn_func&lt;/span&gt;
    &lt;span class="no"&gt;BLOCK_SPARSE_AVAILABLE&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;True&lt;/span&gt;
&lt;span class="k"&gt;except&lt;/span&gt; &lt;span class="nc"&gt;ModuleNotFoundError&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;block_sparse_attn_func&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;None&lt;/span&gt;
    &lt;span class="no"&gt;BLOCK_SPARSE_AVAILABLE&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;False&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then, where the attention mask is used, fall back to PyTorch's &lt;code&gt;scaled_dot_product_attention&lt;/code&gt; when the kernel isn't there:&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="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;attention_mask&lt;/span&gt; &lt;span class="k"&gt;is&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="kc"&gt;None&lt;/span&gt; &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="no"&gt;BLOCK_SPARSE_AVAILABLE&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;q&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;rearrange&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;q&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"b s (n d) -&amp;gt; b n s d"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;num_heads&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;k&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;rearrange&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="s2"&gt;"b s (n d) -&amp;gt; b n s d"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;num_heads&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;v&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;rearrange&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"b s (n d) -&amp;gt; b n s d"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;num_heads&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;F&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;scaled_dot_product_attention&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;q&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="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;rearrange&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"b n s d -&amp;gt; b s (n d)"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;num_heads&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's dense attention. It ignores FlashVSR's sparse locality mask completely, which costs speed, and more on that below.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Turn on AOTriton, or SDPA will eat all your memory
&lt;/h2&gt;

&lt;p&gt;On ROCm, &lt;code&gt;scaled_dot_product_attention&lt;/code&gt; only uses a fused flash-attention kernel (AOTriton) on consumer RDNA3 cards if you ask for it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="kd"&gt;export&lt;/span&gt; &lt;span class="nv"&gt;TORCH_ROCM_AOTRITON_ENABLE_EXPERIMENTAL&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Without it, PyTorch quietly falls back to the math backend, which builds the full attention matrix. For FlashVSR's sequence lengths that's tens of gigabytes. You won't get a helpful error, just an out-of-memory crash, or a process that dies with no traceback at all.&lt;/p&gt;

&lt;p&gt;If you only remember one thing from this post, make it this variable.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. The bug that turned every frame into noise
&lt;/h2&gt;

&lt;p&gt;Dense attention throws away information the model was trained with, so the obvious next step was to keep it. I expanded FlashVSR's block-level sparsity mask into a token-level boolean mask and passed it to SDPA as &lt;code&gt;attn_mask&lt;/code&gt;. In theory that gives you the same attention pattern as the CUDA kernel, just slower.&lt;/p&gt;

&lt;p&gt;In practice every output frame was pure latent noise. Not slightly wrong, not blurry: static.&lt;/p&gt;

&lt;p&gt;The likely culprit is mask polarity (SDPA's boolean &lt;code&gt;attn_mask&lt;/code&gt; means "True = attend", and it's very easy to invert the block mask's meaning when expanding it), possibly combined with how the expanded mask interacts with the fused kernel. I didn't fully chase it down, because the plain dense path produced correct, clean output and the masked one wasn't faster on this card anyway: once you hand SDPA an arbitrary mask, you lose most of the fused-kernel advantage.&lt;/p&gt;

&lt;p&gt;So the shipped path is dense, and mask expansion stays behind an off-by-default experiment flag. If you try this yourself and get noise, turn the mask off before you start debugging anything else.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Memory: ROCm can't defragment, so don't let it fragment
&lt;/h2&gt;

&lt;p&gt;The NVIDIA advice for long diffusion runs is &lt;code&gt;PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True&lt;/code&gt;. That wasn't available to me on ROCm, and FlashVSR's streaming loop fragments VRAM badly without it. Eventually even a 176 MiB allocation fails on a card with gigabytes "free".&lt;/p&gt;

&lt;p&gt;Three patches fixed it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Offload the DiT before decoding.&lt;/strong&gt; FlashVSR's TCDecoder runs after the diffusion step in each chunk, with the DiT still resident. Moving it off first gives the decoder room:&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="nb"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;load_models_to_device&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="p"&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;cuda&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;empty_cache&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;cur_frames&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;TCDecoder&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;decode_video&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="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nb"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;load_models_to_device&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'dit'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Stream decoded frames to the CPU.&lt;/strong&gt; The decoder accumulates finished frames on the GPU and stacks them at the end. At 1280×960 that's around 3 GB of extra residency, scattered across the heap. Moving each finished frame to host memory as it's produced keeps the GPU heap compact:&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;out&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;xt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;to&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"cpu"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;non_blocking&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;False&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Clean up after every streaming segment.&lt;/strong&gt; Delete the per-segment tensors and empty the cache before the next DiT step, so the allocator can hand back contiguous blocks:&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="k"&gt;del&lt;/span&gt; &lt;span class="n"&gt;cur_frames&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;cur_latents&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;noise_pred_posi&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;cur_LQ_frame&lt;/span&gt;
&lt;span class="n"&gt;gc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;collect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&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;cuda&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;empty_cache&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;None of these change the output. They just stop the run from dying halfway through.&lt;/p&gt;

&lt;h2&gt;
  
  
  6. Pick a resolution the card can actually do
&lt;/h2&gt;

&lt;p&gt;With all of the above, 16 GB comfortably handles 2× upscaling from an input around 320 to 384 pixels wide. A 512-wide input ran one streaming step and then died without a traceback. Some other knobs I tried:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;fp16 over bf16.&lt;/strong&gt; bf16 was less reliable on RDNA3 in my runs.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;DiT tiling&lt;/strong&gt; (&lt;code&gt;tile_dit&lt;/code&gt;) fits larger inputs into memory, but was about 8× slower. I only use it as a last resort.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;For low-res sources, keep the native width.&lt;/strong&gt; For a 320×240 clip, I found it better to shorten the chunks (2 s down to 1 s) than to downscale to 256 wide first. Downscaling a source that small throws away detail you can't get back.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  7. Don't trust WSL's idea of how much RAM you have
&lt;/h2&gt;

&lt;p&gt;Inside WSL, &lt;code&gt;psutil&lt;/code&gt; reports the VM's memory cap, not the machine's. On a 32 GB host, WSL showed about 10 GB, and my memory-tuning code treated it as a small machine. It reloaded the model every two chunks to be safe, which roughly doubled the run time.&lt;/p&gt;

&lt;p&gt;Two fixes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Raise the VM limit in &lt;code&gt;%UserProfile%\.wslconfig&lt;/code&gt; (&lt;code&gt;memory=12GB&lt;/code&gt; on a 32 GB host), then run &lt;code&gt;wsl --shutdown&lt;/code&gt; once.&lt;/li&gt;
&lt;li&gt;Pass the real host RAM in from the Windows side as an environment variable, and size things from that.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Keeping one model process warm across chunks, and restarting it every 12 or so instead of every 2, was the single biggest speedup after getting attention right.&lt;/p&gt;

&lt;h2&gt;
  
  
  How fast is it?
&lt;/h2&gt;

&lt;p&gt;My first working run took about 230 seconds for 2 seconds of 384×384 video upscaled to 768×768. After the memory and warm-worker fixes, a realistic number on the 7800 XT is about a minute of processing per second of 320 to 360p source.&lt;/p&gt;

&lt;p&gt;That's fine for clips and highlights. A full 2-hour tape is not a reasonable job for this card, and dense attention is the reason. NVIDIA cards with the real sparse kernel are much faster.&lt;/p&gt;

&lt;h2&gt;
  
  
  The quality catch: diffusion warps on motion
&lt;/h2&gt;

&lt;p&gt;Getting FlashVSR to run is half the story. On real footage, especially fast motion like a kick or a head turn, pure FlashVSR output tends to warp: edges drift a few pixels from where they are in the source, and faces can subtly change shape between frames.&lt;/p&gt;

&lt;p&gt;What worked better for me was using it as a detail donor rather than the final picture:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Run a conventional super-resolution model (Real-ESRGAN class) on the source. It's less detailed, but its geometry stays put.&lt;/li&gt;
&lt;li&gt;Run FlashVSR and line its output up with that base.&lt;/li&gt;
&lt;li&gt;Take only the high-frequency detail from FlashVSR, and only where the two agree at low frequency. Where they disagree (the warp), fall back to the base.&lt;/li&gt;
&lt;li&gt;Smooth that detail layer over time a little, so it doesn't shimmer.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The result keeps FlashVSR's texture and the source's shape. It also gets rid of the bright "sticker outline" that shows up around moving people when you sharpen a slightly misaligned diffusion output.&lt;/p&gt;

&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;p&gt;If you want FlashVSR on an AMD card:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Use WSL2 with a system ROCm install, and swap in the system &lt;code&gt;libhsa-runtime64.so&lt;/code&gt; if PyTorch can't see the GPU.&lt;/li&gt;
&lt;li&gt;Make Block-Sparse-Attention optional and fall back to dense SDPA.&lt;/li&gt;
&lt;li&gt;Set &lt;code&gt;TORCH_ROCM_AOTRITON_ENABLE_EXPERIMENTAL=1&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Don't pass an expanded sparsity mask to SDPA unless you enjoy static.&lt;/li&gt;
&lt;li&gt;Offload the DiT before decoding, move decoded frames to the CPU, and clean up after every segment.&lt;/li&gt;
&lt;li&gt;Stay around 320 to 384 px input width on 16 GB, in fp16.&lt;/li&gt;
&lt;li&gt;Tell your code the real host RAM, not WSL's.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;I packaged all of this into &lt;a href="https://phoenixlabs.space/upscaler" rel="noopener noreferrer"&gt;Phoenix Upscaler&lt;/a&gt;, a desktop app for restoring old video (tapes, DVDs, early phone footage), where the AMD generative mode sets up WSL and ROCm for you. The &lt;a href="https://phoenixlabs.space/upscaler-guide" rel="noopener noreferrer"&gt;setup guide&lt;/a&gt; covers what it installs, and there's a longer write-up on &lt;a href="https://phoenixlabs.space/restore-old-video" rel="noopener noreferrer"&gt;restoring old video in general&lt;/a&gt;, plus a fuller &lt;a href="https://phoenixlabs.space/ai-video-upscaling-amd-gpu" rel="noopener noreferrer"&gt;guide to AI upscaling on AMD GPUs&lt;/a&gt; and a note on &lt;a href="https://phoenixlabs.space/deinterlace-video" rel="noopener noreferrer"&gt;deinterlacing tape footage&lt;/a&gt;. But everything above works on a plain FlashVSR-Pro checkout too.&lt;/p&gt;

&lt;p&gt;If you get it running on a different RDNA card (a 7900 XTX, or anything RDNA2), I'd like to hear what resolution it handles.&lt;/p&gt;

</description>
      <category>machinelearning</category>
      <category>ai</category>
      <category>python</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
