<?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: Arifa Chan</title>
    <description>The latest articles on DEV Community by Arifa Chan (@arifachan).</description>
    <link>https://dev.to/arifachan</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%2F894101%2Fd8ee9b1c-dadb-4cb1-9db7-4800832895a9.jpg</url>
      <title>DEV Community: Arifa Chan</title>
      <link>https://dev.to/arifachan</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/arifachan"/>
    <language>en</language>
    <item>
      <title>Fix: resolve Qwen3 text encoder loading issues for FP8 and GGUF formats</title>
      <dc:creator>Arifa Chan</dc:creator>
      <pubDate>Sun, 26 Jul 2026 14:44:41 +0000</pubDate>
      <link>https://dev.to/arifachan/fix-resolve-qwen3-text-encoder-loading-issues-for-fp8-and-gguf-formats-2bl</link>
      <guid>https://dev.to/arifachan/fix-resolve-qwen3-text-encoder-loading-issues-for-fp8-and-gguf-formats-2bl</guid>
      <description>&lt;h2&gt;
  
  
  Description
&lt;/h2&gt;

&lt;p&gt;This PR resolves two separate crashing issues that occur when loading the Qwen3 text encoder in different quantized formats (FP8 Safetensors and GGUF) alongside the Z-Image model.&lt;/p&gt;

&lt;h3&gt;
  
  
  Issue 1: Missing &lt;code&gt;lm_head.weight&lt;/code&gt; in FP8 Safetensors
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Error Traceback:&lt;/strong&gt; &lt;code&gt;Exception: Missing keys: ['lm_head.weight']&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Root Cause:&lt;/strong&gt; Many quantized FP8 checkpoints intentionally drop the &lt;code&gt;lm_head.weight&lt;/code&gt; key to save disk space, as it is tied to &lt;code&gt;model.embed_tokens.weight&lt;/code&gt;. However, when &lt;code&gt;fast_load_transformers_model&lt;/code&gt; is called, &lt;code&gt;mmgp/offload.py&lt;/code&gt; performs a strict key check and crashes.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Solution:&lt;/strong&gt; Implemented a &lt;code&gt;unified_preprocessor&lt;/code&gt; (with a &lt;code&gt;_fix_qwen_fp8_sd&lt;/code&gt; module-level helper) that intercepts the state dictionary as it loads. It dynamically aliases the &lt;code&gt;model.embed_tokens.weight&lt;/code&gt; memory reference into the &lt;code&gt;lm_head.weight&lt;/code&gt; slot before the strict check occurs, bypassing the error without wasting VRAM on duplicated tensors.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Issue 2: SDPA Dtype Mismatch in GGUF
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Error Traceback:&lt;/strong&gt; &lt;code&gt;RuntimeError: Expected query, key, and value to have the same dtype, but got query.dtype: float key.dtype: float and value.dtype: struct c10::BFloat16 instead.&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Root Cause:&lt;/strong&gt; When using GGUF text encoders (e.g., &lt;code&gt;Q4_K_M&lt;/code&gt;), the underlying integration provides the &lt;code&gt;Value&lt;/code&gt; tensor in &lt;code&gt;bfloat16&lt;/code&gt;, while Hugging Face &lt;code&gt;transformers&lt;/code&gt; computes the RoPE for &lt;code&gt;Query&lt;/code&gt; and &lt;code&gt;Key&lt;/code&gt; in &lt;code&gt;float32&lt;/code&gt;. PyTorch's native SDPA strictly requires all three to share the exact same data type, causing an immediate crash.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Solution:&lt;/strong&gt; Forced the text encoder to a uniform precision state directly after loading by calling &lt;code&gt;text_encoder.to(dtype)&lt;/code&gt;. This aligns all attention projections, allowing HF's native SDPA to run seamlessly without needing to alter the core attention backend.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Changes Made in &lt;code&gt;models/z_image/z_image_main.py&lt;/code&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Injected a state dictionary preprocessor to handle missing tied embedding weights on the fly.&lt;/li&gt;
&lt;li&gt;Added a &lt;code&gt;.to(dtype)&lt;/code&gt; cast immediately after &lt;code&gt;offload.fast_load_transformers_model&lt;/code&gt; completes to enforce strict dtype uniformity.&lt;/li&gt;
&lt;/ul&gt;


&lt;div class="ltag_github-liquid-tag"&gt;
  &lt;h1&gt;
    &lt;a href="https://github.com/deepbeepmeep/Wan2GP/pull/1904" rel="noopener noreferrer"&gt;
      &lt;img class="github-logo" alt="GitHub logo" src="https://assets.dev.to/assets/github-logo-5a155e1f9a670af7944dd5e12375bc76ed542ea80224905ecaf878b9157cdefc.svg"&gt;
      &lt;span class="issue-title"&gt;
        Fix: resolve Qwen3 text encoder loading issues for FP8 and GGUF formats
      &lt;/span&gt;
      &lt;span class="issue-number"&gt;#1904&lt;/span&gt;
    &lt;/a&gt;
  &lt;/h1&gt;
  &lt;div class="github-thread"&gt;
    &lt;div class="timeline-comment-header"&gt;
      &lt;a href="https://github.com/arifanchan" rel="noopener noreferrer"&gt;
        &lt;img class="github-liquid-tag-img" src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Favatars.githubusercontent.com%2Fu%2F128233413%3Fv%3D4" alt="arifanchan avatar"&gt;
      &lt;/a&gt;
      &lt;div class="timeline-comment-header-text"&gt;
        &lt;strong&gt;
          &lt;a href="https://github.com/arifanchan" rel="noopener noreferrer"&gt;arifanchan&lt;/a&gt;
        &lt;/strong&gt; posted on &lt;a href="https://github.com/deepbeepmeep/Wan2GP/pull/1904" rel="noopener noreferrer"&gt;&lt;time&gt;Jun 13, 2026&lt;/time&gt;&lt;/a&gt;
      &lt;/div&gt;
    &lt;/div&gt;
    &lt;div class="ltag-github-body"&gt;
      &lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;Description&lt;/h2&gt;
&lt;span class="octicon octicon-link"&gt;&lt;/span&gt;
&lt;/div&gt;
&lt;p&gt;This PR resolves two separate crashing issues that occur when loading the Qwen3 text encoder in different quantized formats (FP8 Safetensors and GGUF) alongside the Z-Image model.&lt;/p&gt;
&lt;div class="markdown-heading"&gt;
&lt;h3 class="heading-element"&gt;Issue 1: Missing &lt;code&gt;lm_head.weight&lt;/code&gt; in FP8 Safetensors&lt;/h3&gt;
&lt;span class="octicon octicon-link"&gt;&lt;/span&gt;
&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;Error Traceback:&lt;/strong&gt; &lt;code&gt;Exception: Missing keys: ['lm_head.weight']&lt;/code&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Root Cause:&lt;/strong&gt; Many quantized FP8 checkpoints intentionally drop the &lt;code&gt;lm_head.weight&lt;/code&gt; key to save disk space, as it is tied to &lt;code&gt;model.embed_tokens.weight&lt;/code&gt;. However, when &lt;code&gt;fast_load_transformers_model&lt;/code&gt; is called, &lt;code&gt;mmgp/offload.py&lt;/code&gt; performs a strict key check and crashes.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Solution:&lt;/strong&gt; Implemented a &lt;code&gt;unified_preprocessor&lt;/code&gt; (with a &lt;code&gt;_fix_qwen_fp8_sd&lt;/code&gt; module-level helper) that intercepts the state dictionary as it loads. It dynamically aliases the &lt;code&gt;model.embed_tokens.weight&lt;/code&gt; memory reference into the &lt;code&gt;lm_head.weight&lt;/code&gt; slot before the strict check occurs, bypassing the error without wasting VRAM on duplicated tensors.&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="markdown-heading"&gt;
&lt;h3 class="heading-element"&gt;Issue 2: SDPA Dtype Mismatch in GGUF&lt;/h3&gt;
&lt;span class="octicon octicon-link"&gt;&lt;/span&gt;
&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;Error Traceback:&lt;/strong&gt; &lt;code&gt;RuntimeError: Expected query, key, and value to have the same dtype, but got query.dtype: float key.dtype: float and value.dtype: struct c10::BFloat16 instead.&lt;/code&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Root Cause:&lt;/strong&gt; When using GGUF text encoders (e.g., &lt;code&gt;Q4_K_M&lt;/code&gt;), the underlying integration provides the &lt;code&gt;Value&lt;/code&gt; tensor in &lt;code&gt;bfloat16&lt;/code&gt;, while Hugging Face &lt;code&gt;transformers&lt;/code&gt; computes the RoPE for &lt;code&gt;Query&lt;/code&gt; and &lt;code&gt;Key&lt;/code&gt; in &lt;code&gt;float32&lt;/code&gt;. PyTorch's native SDPA strictly requires all three to share the exact same data type, causing an immediate crash.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Solution:&lt;/strong&gt; Forced the text encoder to a uniform precision state directly after loading by calling &lt;code&gt;text_encoder.to(dtype)&lt;/code&gt;. This aligns all attention projections, allowing HF's native SDPA to run seamlessly without needing to alter the core attention backend.&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="markdown-heading"&gt;
&lt;h3 class="heading-element"&gt;Changes Made in &lt;code&gt;models/z_image/z_image_main.py&lt;/code&gt;
&lt;/h3&gt;
&lt;span class="octicon octicon-link"&gt;&lt;/span&gt;
&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;Injected a state dictionary preprocessor to handle missing tied embedding weights on the fly.&lt;/li&gt;
&lt;li&gt;Added a &lt;code&gt;.to(dtype)&lt;/code&gt; cast immediately after &lt;code&gt;offload.fast_load_transformers_model&lt;/code&gt; completes to enforce strict dtype uniformity.&lt;/li&gt;
&lt;/ul&gt;

    &lt;/div&gt;
    &lt;div class="gh-btn-container"&gt;&lt;a class="gh-btn" href="https://github.com/deepbeepmeep/Wan2GP/pull/1904" rel="noopener noreferrer"&gt;View on GitHub&lt;/a&gt;&lt;/div&gt;
  &lt;/div&gt;
&lt;/div&gt;


</description>
      <category>ai</category>
      <category>opensource</category>
      <category>programming</category>
      <category>python</category>
    </item>
    <item>
      <title>Iterate phrase string through python dict that contains one...</title>
      <dc:creator>Arifa Chan</dc:creator>
      <pubDate>Mon, 18 Jul 2022 19:21:09 +0000</pubDate>
      <link>https://dev.to/arifachan/iterate-phrase-string-through-python-dict-that-contains-one-2bcf</link>
      <guid>https://dev.to/arifachan/iterate-phrase-string-through-python-dict-that-contains-one-2bcf</guid>
      <description>&lt;div class="ltag__stackexchange--container"&gt;
  &lt;div class="ltag__stackexchange--title-container"&gt;
    
      &lt;div class="ltag__stackexchange--title"&gt;
        &lt;div class="ltag__stackexchange--header"&gt;
          &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--7Gn-iPj_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev.to/assets/stackoverflow-logo-b42691ae545e4810b105ee957979a853a696085e67e43ee14c5699cf3e890fb4.svg" alt=""&gt;
          &lt;a href="https://stackoverflow.com/questions/73027062/iterate-phrase-string-through-python-dict-that-contains-one-two-or-more-word-in" rel="noopener noreferrer"&gt;
            Iterate phrase string through python dict that contains one, two or more word in key and add the strings to a list if exist in dict keys
          &lt;/a&gt;
        &lt;/div&gt;
        &lt;div class="ltag__stackexchange--post-metadata"&gt;
          &lt;span&gt;Jul 18 '22&lt;/span&gt;
            &lt;span&gt;Comments: 1&lt;/span&gt;
            &lt;span&gt;Answers: 0&lt;/span&gt;
        &lt;/div&gt;
      &lt;/div&gt;
      &lt;a class="ltag__stackexchange--score-container" href="https://stackoverflow.com/questions/73027062/iterate-phrase-string-through-python-dict-that-contains-one-two-or-more-word-in" rel="noopener noreferrer"&gt;
        &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Y9mJpuJP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev.to/assets/stackexchange-arrow-up-eff2e2849e67d156181d258e38802c0b57fa011f74164a7f97675ca3b6ab756b.svg" alt=""&gt;
        &lt;div class="ltag__stackexchange--score-number"&gt;
          0
        &lt;/div&gt;
        &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--wif5Zq3z--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev.to/assets/stackexchange-arrow-down-4349fac0dd932d284fab7e4dd9846f19a3710558efde0d2dfd05897f3eeb9aba.svg" alt=""&gt;
      &lt;/a&gt;
    
  &lt;/div&gt;
  &lt;div class="ltag__stackexchange--body"&gt;
    
&lt;p&gt;I want to iterate some string from voice input through python dict that contains one, two or more word in key and add the strings to a list if exist in dict keys. I know how to add the string  (&lt;code&gt;voiceinput&lt;/code&gt;) to a new list (&lt;code&gt;fruit_cart&lt;/code&gt;)…&lt;/p&gt;
    
  &lt;/div&gt;
  &lt;div class="ltag__stackexchange--btn--container"&gt;
    &lt;a href="https://stackoverflow.com/questions/73027062/iterate-phrase-string-through-python-dict-that-contains-one-two-or-more-word-in" class="ltag__stackexchange--btn" rel="noopener noreferrer"&gt;Open Full Question&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;


</description>
    </item>
  </channel>
</rss>
