ROCm: disable cache in generate and fix GPT-OSS dtype#494
ROCm: disable cache in generate and fix GPT-OSS dtype#494danielhanchen wants to merge 5 commits intomainfrom
Conversation
Summary of ChangesHello @danielhanchen, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly enhances compatibility and stability for Unsloth users running on ROCm (AMD GPUs). It addresses critical issues by disabling caching during generation, ensuring correct data type handling for GPT-OSS models, and deactivating certain experimental backends by default, all aimed at preventing common ROCm-specific errors and improving overall reliability. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces several important fixes and compatibility improvements specifically for ROCm (HIP) environments. The changes disable AITER and ROCm RoPE backend by default, ensure correct data type handling for GPT-OSS expert inputs, and force use_cache=False during generation to prevent HSA exceptions. These adjustments are crucial for enhancing the stability and functionality of the system on ROCm hardware. The patches are well-isolated and include mechanisms to prevent re-patching, contributing to overall maintainability.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: db69274f88
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| original_generate = generation_utils.GenerationMixin.generate | ||
|
|
||
| def generate(self, *args, **kwargs): | ||
| kwargs["use_cache"] = False |
There was a problem hiding this comment.
Keep cache enabled for assisted generation on HIP
Overwriting kwargs["use_cache"] to False unconditionally makes assisted decoding fail on ROCm whenever callers use assistant_model, prompt_lookup_num_tokens, or assistant_early_exit. In transformers (checked 4.57.6), the assisted path raises ValueError("assisted generate requires use_cache=True") when model_kwargs["use_cache"] is false, so this patch turns those valid generate() calls into hard failures instead of just applying a perf workaround.
Useful? React with 👍 / 👎.
|
Quick status check:
|
|
Validation update with additional ROCm rechecks and a follow-up commit. What changed
Why
Evidence (ROCm, single GPU)
Notes on compatibility
Commit
|
|
Follow-up tweak on the compiler router cast. Change
Why
Validation
Commit
|
|
Added a targeted GRPO VLM fix for Gemma3 Vision on ROCm. Root cause
Change
Validation
|
|
Added follow-up ROCm notebook fixes for audio/CSM paths.
What changed:
Validation evidence (ROCm runs):
|
| del sys.modules["torchcodec"] | ||
| except Exception: | ||
| pass | ||
| pass |
| return {"array": data, "sampling_rate": sr} | ||
| except Exception: | ||
| raise | ||
| pass |
| force = True, | ||
| match_level = "relaxed", | ||
| ) | ||
| pass |
| sys.meta_path.insert(0, _DeepseekOCRHook()) | ||
| except Exception as e: | ||
| return raise_error("DeepseekOCRModel", e) | ||
| pass |
|
|
||
| generation_utils.GenerationMixin.generate = generate | ||
| generation_utils.GenerationMixin._unsloth_rocm_generate_patched = True | ||
| pass |
| attn_output = attn_output.squeeze(1) | ||
| attn_output = self.o_proj(attn_output) | ||
| return attn_output, attn_weights | ||
| pass |
| force = True, | ||
| match_level = "relaxed", | ||
| ) | ||
| pass |
| else: | ||
| raw_speech = _resample_array(raw_speech, sampling_rate, target_sr) | ||
| return original_call(self, raw_speech, sampling_rate = target_sr, *args, **kwargs) | ||
| pass |
| force = True, | ||
| match_level = "relaxed", | ||
| ) | ||
| pass |
| asr.ffmpeg_read = ffmpeg_read | ||
| except Exception: | ||
| pass | ||
| pass |
|
Superseding my prior malformed CLI comment with corrected content. Re-review update for PR #494:
No new code changes were pushed to this branch in this pass. The only pushed cleanup in this re-review cycle was in unsloth PR #4021 to remove a duplicate call site. |
| ) -> torch.Tensor: | ||
| """Forward using grouped_mm or loop fallback with LoRA support.""" | ||
| # Keep activations aligned with expert weights to avoid mixed-dtype matmul errors. | ||
| target_dtype = getattr(getattr(self.down_proj, "weight", None), "dtype", None) |
There was a problem hiding this comment.
Are we still seeing any errors? I remember checking both fp16 and bf16
| kwargs["use_cache"] = False | ||
| # HIP-safe generation: drop cache-only kwargs that can route into | ||
| # unsupported codepaths and trigger assert_async failures. | ||
| for key in ( |
There was a problem hiding this comment.
If we're disabling kv cache, we should at least warn when people call .generate
Otherwise we might see a barrage of complaints that inference is slow
PS: How does vLLM handle KVCache for HiP?
| chunk_logits = chunk_hidden_states.to(lm_head.dtype) @ lm_head.t() | ||
| else: | ||
| # Fallback: try projection path and let the underlying matmul raise a | ||
| # precise error if the dimensions are genuinely incompatible. |
There was a problem hiding this comment.
The elif and else can be combined into single call?
Summary
Testing