Commit b6f4e20
[BUG] Fix UlyssesSPAttentionHF.register_with_transformers() crash with PEFT models (#7737)
**Description**
This PR fixes a crash in
`UlyssesSPAttentionHF.register_with_transformers()` when a PEFT-wrapped
model (e.g., `PeftModel`) is passed as the `model_name_or_path`
argument.
**The Issue**
The function previously used an overly strict
`isinstance(model_name_or_path, PreTrainedModel)` check. Since PEFT
models do not subclass `PreTrainedModel` (though they forward to one),
the check would fail. The logic then fell through to the `else` block,
treating the model object as a string path and calling
`AutoConfig.from_pretrained(model_name_or_path)`, which immediately
raised a `TypeError` or `OSError`.
**Changes**
* Updated the logic to use duck-typing: if the input object has a
`.config` attribute, we treat it as a model and access the configuration
directly.
* Hugging Face string paths (Hub IDs or local paths) continue to be
handled by the fallback to `AutoConfig`.
**Validation**
Verified that:
1. PEFT-wrapped models now successfully register without crashing.
2. Standard `PreTrainedModel` objects still register correctly.
3. String paths successfully trigger `AutoConfig.from_pretrained` as
expected.
Fixes #7729
---------
Signed-off-by: Rakshit-gen <sisodiarakshit456@gmail.com>
Co-authored-by: Olatunji Ruwase <tunji.ruwase@snowflake.com>1 parent 377a0d1 commit b6f4e20
File tree
2 files changed
+49
-2
lines changed- deepspeed/runtime/sequence_parallel
- tests/unit/ulysses_alst
2 files changed
+49
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
389 | 389 | | |
390 | 390 | | |
391 | 391 | | |
392 | | - | |
393 | | - | |
| 392 | + | |
| 393 | + | |
394 | 394 | | |
395 | 395 | | |
396 | 396 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
185 | 185 | | |
186 | 186 | | |
187 | 187 | | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
0 commit comments