Skip to content

feat(core): Introduce kBool data type for Qnn ElewiseEqual Op#618

Merged
chenghuaWang merged 4 commits intoUbiquitousLearning:mainfrom
chenghuaWang:wch-main
Jan 30, 2026
Merged

feat(core): Introduce kBool data type for Qnn ElewiseEqual Op#618
chenghuaWang merged 4 commits intoUbiquitousLearning:mainfrom
chenghuaWang:wch-main

Conversation

@chenghuaWang
Copy link
Copy Markdown
Collaborator

@chenghuaWang chenghuaWang commented Jan 30, 2026

Summary by CodeRabbit

  • New Features

    • Added boolean data type support across the system, enabling proper representation and handling of boolean values in operations.
  • Improvements

    • Updated attention head configuration for Qwen3 models.
    • Comparison operations now use the appropriate boolean output type.
  • Documentation

    • Added mobile module documentation outlining future development directions.

✏️ Tip: You can customize this high-level summary in your review settings.

…sor shapes and values before exiting. This aids in troubleshooting during AOT runs.
…ons for improved type handling. Modify tensor output type in EqualOp to use kBool for better logical operations.
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jan 30, 2026

📝 Walkthrough

Walkthrough

This PR introduces comprehensive support for a new boolean data type (kBool) throughout the mllm framework. Changes include defining the kBool type in the core DataTypes system, implementing QNN backend support for boolean mapping, updating the equality comparison operator to output boolean results, and adjusting related Qwen3 model configurations.

Changes

Cohort / File(s) Summary
Boolean Type Definition
mllm/core/DataTypes.hpp, mllm/core/DataTypes.cpp
Introduces new boolean type alias (mllm_bool_t), adds kBool enum entry (value 156), and registers type-info specializations for boolean type in the core type system.
QNN Backend Support
mllm/backends/qnn/QNNUtils.cpp
Adds case handler for kBool datatype in mllmDataTypeToQnnDataType function, mapping boolean to QNN_DATATYPE_BOOL_8.
Equality Operator
mllm/core/aops/CmpOp.cpp
Updates EqualOp::reshape to output kBool type instead of kUInt8 for equality comparison results.
Qwen3 Model Configuration
examples/qwen3_qnn_aot/aot_run.cpp, examples/qwen3_qnn_aot/modeling_qwen_qnn_aot_sha.hpp
Adjusts attention head configuration to use num_key_value_heads instead of num_attention_heads; removes per-head slicing in SHA parameter preparation for q_norm and k_norm weights.
Mobile Documentation
pymllm/mobile/README.md
Adds new README describing mobile directory refactor directions.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • liang1232018
  • oreomaker

Poem

🐰 A hop, a skip, a boolean true,
New kBool types join the mllm crew,
From QNN backends to comparison ops,
Our types now flourish—the logic never stops!
With equality wearing its freshest new coat,
We celebrate features of which we shall gloat! 🥕✨

🚥 Pre-merge checks | ✅ 1 | ❌ 2
❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Description check ⚠️ Warning No pull request description was provided by the author, leaving the description completely empty. Add a detailed description explaining the motivation, implementation details, and testing approach for the kBool data type introduction.
Docstring Coverage ⚠️ Warning Docstring coverage is 28.57% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: introducing a boolean data type (kBool) for the QNN ElementWise Equal operation.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Fix all issues with AI agents
In `@mllm/backends/qnn/aot_rt/PromptProcessor.cpp`:
- Around line 151-153: The unconditional exit(0) in PromptProcessor.cpp inside
the prefill path aborts generation; remove the exit(0) and instead guard the
debug prints (the two print(...) calls referencing output_tensors_) behind a
runtime debug/log flag or use the existing logging facility so they don't
terminate execution—e.g., wrap the print calls in if (debug_enabled) {
print(...); } or replace with a debug log call; ensure prefill continues
normally so logits/sampling are not skipped.

In `@pymllm/mobile/README.md`:
- Line 1: The README sentence is awkward and misses a hyphen: reword it to be
tighter and hyphenate "torch-based" — e.g. change "We should refactor current
pymllm's src to mobile directory. And provide more functionalities for torch
based VLA." to a single clear sentence such as "Refactor pymllm's src into the
mobile directory and provide additional functionality for torch-based VLA."
Update the README.md to use this tightened, hyphenated phrasing.

Comment thread mllm/backends/qnn/aot_rt/PromptProcessor.cpp Outdated
Comment thread pymllm/mobile/README.md
@@ -0,0 +1 @@
We should refactor current pymllm's src to mobile directory. And provide more functionalities for torch based VLA.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Polish wording and hyphenation.

Consider tightening the sentence and hyphenating “torch-based.”

✏️ Suggested edit
-We should refactor current pymllm's src to mobile directory. And provide more functionalities for torch based VLA.
+We should refactor the current pymllm src into the mobile directory and provide more functionality for torch-based VLA.
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
We should refactor current pymllm's src to mobile directory. And provide more functionalities for torch based VLA.
We should refactor the current pymllm src into the mobile directory and provide more functionality for torch-based VLA.
🧰 Tools
🪛 LanguageTool

[grammar] ~1-~1: Use a hyphen to join words.
Context: ...d provide more functionalities for torch based VLA.

(QB_NEW_EN_HYPHEN)

🤖 Prompt for AI Agents
In `@pymllm/mobile/README.md` at line 1, The README sentence is awkward and misses
a hyphen: reword it to be tighter and hyphenate "torch-based" — e.g. change "We
should refactor current pymllm's src to mobile directory. And provide more
functionalities for torch based VLA." to a single clear sentence such as
"Refactor pymllm's src into the mobile directory and provide additional
functionality for torch-based VLA." Update the README.md to use this tightened,
hyphenated phrasing.

…by removing unnecessary slicing, improving efficiency in parameter preparation.
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
examples/qwen3_qnn_aot/modeling_qwen_qnn_aot_sha.hpp (1)

763-804: ⚠️ Potential issue | 🟠 Major

Handle both shared and concatenated q_norm/k_norm weight layouts to avoid shape mismatches.

Line 767 and Line 803 now copy the full orig_weight into every per-head RMSNorm without validating its size. If the checkpoint still stores concatenated weights (num_heads × head_dim or num_kv_heads × head_dim), each per-head RMSNorm will receive an oversized vector and likely fail or normalize incorrectly. Guard the layout and slice only when needed.

🧩 Suggested fix (guard + conditional slicing)
@@
-        for (int h = 0; h < num_heads; ++h) {
+        const int q_weight_numel = orig_weight.numel();
+        MLLM_RT_ASSERT(q_weight_numel == head_dim || q_weight_numel == num_heads * head_dim);
+        for (int h = 0; h < num_heads; ++h) {
           std::string h_str = std::to_string(h);
           // Weight: slice per head
           std::string new_weight_name = layer_prefix + "q_norm." + h_str + ".weight";  // NOLINT
-          params->push(new_weight_name, orig_weight.contiguous().setMemType(kParamsNormal).setName(new_weight_name));
+          Tensor weight_h = orig_weight;
+          if (q_weight_numel != head_dim) {
+            int start_idx = h * head_dim;
+            int end_idx = (h + 1) * head_dim;
+            weight_h = orig_weight.slice({{start_idx, end_idx}}, false);
+          }
+          params->push(new_weight_name, weight_h.contiguous().setMemType(kParamsNormal).setName(new_weight_name));
@@
-        for (int h = 0; h < num_kv_heads; ++h) {
+        const int k_weight_numel = orig_weight.numel();
+        MLLM_RT_ASSERT(k_weight_numel == head_dim || k_weight_numel == num_kv_heads * head_dim);
+        for (int h = 0; h < num_kv_heads; ++h) {
           std::string h_str = std::to_string(h);
           // Weight: slice per head
           std::string new_weight_name = layer_prefix + "k_norm." + h_str + ".weight";  // NOLINT
-          params->push(new_weight_name, orig_weight.contiguous().setMemType(kParamsNormal).setName(new_weight_name));
+          Tensor weight_h = orig_weight;
+          if (k_weight_numel != head_dim) {
+            int start_idx = h * head_dim;
+            int end_idx = (h + 1) * head_dim;
+            weight_h = orig_weight.slice({{start_idx, end_idx}}, false);
+          }
+          params->push(new_weight_name, weight_h.contiguous().setMemType(kParamsNormal).setName(new_weight_name));

@chenghuaWang chenghuaWang merged commit fe05c4f into UbiquitousLearning:main Jan 30, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants