Fix: lora kernel pre-patch applied despite post-patch not applied#2772
Conversation
|
""" WalkthroughThe changes introduce a precondition in the Changes
Sequence Diagram(s)sequenceDiagram
participant Test as Test Function
participant Config as LoRA Config
participant Patch as patch_self_attn_lora
participant Model as Model
participant Apply as apply_lora_kernel_patches
Test->>Patch: Call with Config (lora_dropout > 0)
Patch->>Patch: Check lora_dropout
Patch-->>Test: Return without patching
Test->>Model: Load model and tokenizer
Test->>Apply: Call apply_lora_kernel_patches(Model)
Apply->>Model: Retrieve layers via get_layers
Apply->>Model: Attempt to patch (skipped if dropout > 0)
Apply-->>Test: Model layers remain unpatched
Assessment against linked issues
Assessment against linked issues: Out-of-scope changesNo out-of-scope changes found. Possibly related PRs
Suggested reviewers
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (3)
🚧 Files skipped from review as they are similar to previous changes (3)
✨ Finishing Touches
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
|
Ran test and passed locally but other test failing. Not sure if it's some isolation issue. |
Codecov ReportAttention: Patch coverage is
📢 Thoughts on this report? Let us know! |
| # Only patch if conditions are met | ||
| can_patch = cfg.lora_dropout == 0 | ||
|
|
||
| if not can_patch: | ||
| LOG.warning("Cannot patch self-attention - requires no dropout") | ||
| return | ||
|
|
There was a problem hiding this comment.
move this logic out of this function that does the actual patching, into the caller (def _apply_self_attention_lora_patch) and that will fix the test issue since the test is making sure that it patches.
djsaunde
left a comment
There was a problem hiding this comment.
thanks for catching this!
| # Only patch if conditions are met | ||
| can_patch = cfg.lora_dropout == 0 | ||
| can_patch = ( | ||
| cfg.lora_dropout == 0 if hasattr(cfg, "lora_dropout") else True |
There was a problem hiding this comment.
since it's a DictDefault, isn't hasattr always true?
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
src/axolotl/loaders/patch_manager.py (1)
169-179: LGTM! The precondition check effectively addresses the reported bug.The added guard clause correctly prevents self-attention LoRA patching when dropout is enabled, which aligns with the test failures and warning message observed in the PR comments. This should resolve the issue where pre-patch was applied despite post-patch not being applied.
Consider enhancing type safety for the dropout comparison:
- can_patch = ( - self.cfg.lora_dropout == 0 - if hasattr(self.cfg, "lora_dropout") - else True - ) # default to True if lora_dropout is not set + can_patch = True # default to True if lora_dropout is not set + if hasattr(self.cfg, "lora_dropout"): + dropout_val = getattr(self.cfg, "lora_dropout", 0) + can_patch = isinstance(dropout_val, (int, float)) and dropout_val == 0Note: This change may impact backward compatibility for configurations that previously had non-zero dropout values and relied on patching being applied anyway.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
src/axolotl/loaders/patch_manager.py(1 hunks)src/axolotl/monkeypatch/lora_kernels.py(2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- src/axolotl/monkeypatch/lora_kernels.py
⏰ Context from checks skipped due to timeout of 90000ms (8)
- GitHub Check: PyTest from Source Dist (3.11, 2.7.0)
- GitHub Check: PyTest from Source Dist (3.11, 2.6.0)
- GitHub Check: PyTest from Source Dist (3.11, 2.5.1)
- GitHub Check: PyTest (3.11, 2.6.0)
- GitHub Check: PyTest (3.11, 2.7.0)
- GitHub Check: PyTest (3.11, 2.5.1)
- GitHub Check: pre-commit
- GitHub Check: pre-commit
7f1329d to
e4af596
Compare
Description
Fix #2770
Motivation and Context
How has this been tested?
Added test and manual run before/after to ensure error appears and got fixed
Screenshots (if appropriate)
Types of changes
Social Handles (Optional)
Summary by CodeRabbit
Bug Fixes
Tests