1
0
Fork 0
mirror of https://github.com/p-e-w/heretic.git synced 2026-12-03 18:42:57 +07:00

[PR #17] [MERGED] Fix multi-GPU support and memory management #239

Closed
opened 2026-11-01 04:19:07 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/p-e-w/heretic/pull/17
Author: @kldzj
Created: 11/17/2025
Status: ✅ Merged
Merged: 11/18/2025
Merged by: @p-e-w

Base: master ← Head: master


📝 Commits (10+)

  • c1bdeca Ensure projector is on the same device as the matrix for multi-GPU support
  • 32aefea Optimize memory management for loaded model weights
  • 16a44de Refactor memory management by removing unnecessary gc.collect() calls
  • 01a1a7e Merge branch 'p-e-w:master' into master
  • 4663606 Optimize memory usage (#1)
  • b71d328 Fix broken file
  • 74771cf Remove unnecessary deletions
  • 74d8491 Remove unnecessary empty_cache() calls
  • 3647d4a Remove unused import of gc
  • 0ff072b Duplicate gc.collect call in empty_cache()

📊 Changes

3 files changed (+11 additions, -1 deletions)

View changed files

📝 src/heretic/main.py (+6 -0)
📝 src/heretic/model.py (+3 -1)
📝 src/heretic/utils.py (+2 -0)

📄 Description

Problem

  • Device mismatch errors: RuntimeError: Expected all tensors to be on the same device, but got mat2 is on cuda:1, different from other tensors on cuda:0
  • Out-of-memory errors after 1-2 trials despite reloading the model

Solution

  • Move projectors to correct device before each matrix operation
  • Add gc.collect() + empty_cache() before model reloads and after trials

Result

Models with device_map="auto" now run successfully across multiple GPUs without device mismatches or memory accumulation between trials.

Successfully abliterated gpt-oss-120b on 8x B200:

Also confirmed to be working using 4x H200.


Fixes #8


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/p-e-w/heretic/pull/17 **Author:** [@kldzj](https://github.com/kldzj) **Created:** 11/17/2025 **Status:** ✅ Merged **Merged:** 11/18/2025 **Merged by:** [@p-e-w](https://github.com/p-e-w) **Base:** `master` ← **Head:** `master` --- ### 📝 Commits (10+) - [`c1bdeca`](https://github.com/p-e-w/heretic/commit/c1bdeca5c6bcf6c61afe33db753f727e18b9bae9) Ensure projector is on the same device as the matrix for multi-GPU support - [`32aefea`](https://github.com/p-e-w/heretic/commit/32aefea0e7e785aafc0ce018cac921fbf2e65c33) Optimize memory management for loaded model weights - [`16a44de`](https://github.com/p-e-w/heretic/commit/16a44de0ed937fd6a1afe9bda1431ab57cb03c5a) Refactor memory management by removing unnecessary gc.collect() calls - [`01a1a7e`](https://github.com/p-e-w/heretic/commit/01a1a7ed828569863f4dd691b41c4922af40e3d9) Merge branch 'p-e-w:master' into master - [`4663606`](https://github.com/p-e-w/heretic/commit/4663606bfec8ca97a5549224e9afdac1117e7d81) Optimize memory usage (#1) - [`b71d328`](https://github.com/p-e-w/heretic/commit/b71d3287ebd68487275869b34e51f031f5b92822) Fix broken file - [`74771cf`](https://github.com/p-e-w/heretic/commit/74771cfe05ffd708c53ca5f5e01a29b4413d6631) Remove unnecessary deletions - [`74d8491`](https://github.com/p-e-w/heretic/commit/74d849126ba436ca44633ae07ac54ad288706647) Remove unnecessary empty_cache() calls - [`3647d4a`](https://github.com/p-e-w/heretic/commit/3647d4aaf1c6e63b16e490bd0053d4786cb1b9e3) Remove unused import of gc - [`0ff072b`](https://github.com/p-e-w/heretic/commit/0ff072b7cf81e8a03b6cb5229f219d5e77fe3510) Duplicate `gc.collect` call in `empty_cache()` ### 📊 Changes **3 files changed** (+11 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `src/heretic/main.py` (+6 -0) 📝 `src/heretic/model.py` (+3 -1) 📝 `src/heretic/utils.py` (+2 -0) </details> ### 📄 Description ## Problem - Device mismatch errors: `RuntimeError: Expected all tensors to be on the same device, but got mat2 is on cuda:1, different from other tensors on cuda:0` - Out-of-memory errors after 1-2 trials despite reloading the model ## Solution - Move projectors to correct device before each matrix operation - Add `gc.collect()` + `empty_cache()` before model reloads and after trials ## Result Models with `device_map="auto"` now run successfully across multiple GPUs without device mismatches or memory accumulation between trials. Successfully abliterated gpt-oss-120b on 8x B200: - [kldzj/gpt-oss-120b-heretic](https://huggingface.co/kldzj/gpt-oss-120b-heretic) (MXFP4) - [kldzj/gpt-oss-120b-heretic-bf16](https://huggingface.co/kldzj/gpt-oss-120b-heretic-bf16) (BF16) - [kldzj/gpt-oss-120b-heretic-v2](https://huggingface.co/kldzj/gpt-oss-120b-heretic-v2) (MXFP4, lower KL divergence) - [kldzj/gpt-oss-120b-heretic-v2-bf16](https://huggingface.co/kldzj/gpt-oss-120b-heretic-v2-bf16) (BF16, lower KL divergence) Also confirmed to be working using 4x H200. --- Fixes #8 --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-01 04:19:07 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
p-e-w/heretic#239
No description provided.