mirror of
https://github.com/p-e-w/heretic.git
synced 2026-12-03 20:44:21 +07:00
[GH-ISSUE #61] Support aya-expanse-32b-Q4-mlx #28
Labels
No labels
bug
enhancement
enhancement
pull-request
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
p-e-w/heretic#28
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @rigin on GitHub (Dec 2, 2025).
Original GitHub issue: https://github.com/p-e-w/heretic/issues/61
Can you tell me what needs to be added to the settings and where?
Loading model F:\LLMs\aya-expanse-32b-Q4-mlx...
quant_methodattribute. Make sure that the model hasbeen correctly quantized)
quant_methodattribute. Make sure that the model hasbeen correctly quantized)
quant_methodattribute. Make sure that the model hasbeen correctly quantized)
@Vinay-Umrethe commented on GitHub (Dec 2, 2025):
Are you using up to date versions of
transformersandbitsandbytesTry this:@rigin commented on GitHub (Dec 2, 2025):
It didn't help. The error remains.
@Vinay-Umrethe commented on GitHub (Dec 2, 2025):
not sure which model you are using exactly, is that a GGUF ?
maybe you can try this one
2z299/aya-expanse-32b-bnb-4bithttps://huggingface.co/2z299/aya-expanse-32b-bnb-4bit@rigin commented on GitHub (Dec 2, 2025):
No, I know about GGUF, I use safetensors options. Okay, I'll give it a try.
@Vinay-Umrethe commented on GitHub (Dec 2, 2025):
this one is quantized with
bnbthe one you used was MLX likely forapplechips so dtype: auto didn't worked@rigin commented on GitHub (Dec 2, 2025):
The last option was read and launched. Let's see how the process goes. This is the first quantized model that I have been able to download.
@Vinay-Umrethe commented on GitHub (Dec 2, 2025):
sounds good, if the model weights are now downloading... means the
config.jsondtype worked.@rigin commented on GitHub (Dec 2, 2025):
Unfortunately, no. The model has loaded, and the number of tokens has been tested, but an error occurs during the first cycle of the calculation.
Abliterating...
[W 2025-12-02 16:11:06,972] Trial 0 failed with parameters: {'direction_scope': 'global', 'direction_index': 32.135504850155414, 'attn.o_proj.max_weight': 1.132954299787842, 'attn.o_proj.max_weight_position': 23.74937331043737, 'attn.o_proj.min_weight': 0.6690000108980544, 'attn.o_proj.min_weight_distance': 1.3085894434224952, 'mlp.down_proj.max_weight': 1.0086062192607672, 'mlp.down_proj.max_weight_position': 23.825336062440016, 'mlp.down_proj.min_weight': 0.21770223208254313, 'mlp.down_proj.min_weight_distance': 7.646333120329111} because of the following error: RuntimeError('mat1 and mat2 shapes cannot be multiplied (8192x8192 and 100663296x1)').
Traceback (most recent call last):
File "C:\Users\vadim\anaconda3\envs\heretic\Lib\site-packages\optuna\study_optimize.py", line 205, in run_trial
value_or_values = func(trial)
File "C:\Users\vadim\anaconda3\envs\heretic\Lib\site-packages\heretic\main.py", line 363, in objective_wrapper
return objective(trial)
File "C:\Users\vadim\anaconda3\envs\heretic\Lib\site-packages\heretic\main.py", line 341, in objective
model.abliterate(refusal_directions, direction_index, parameters)
~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\vadim\anaconda3\envs\heretic\Lib\site-packages\heretic\model.py", line 239, in abliterate
matrix.sub(weight * (device_projector @ matrix))
~~~~~~~~~~~~~~~~~^~~~~~~~
RuntimeError: mat1 and mat2 shapes cannot be multiplied (8192x8192 and 100663296x1)
[W 2025-12-02 16:11:06,975] Trial 0 failed with value None.
╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮
│ in _run_module_as_main:198 │
│ in _run_code:88 │
│ │
│ in :6 │
│ │
│ 3 if name == 'main': │
│ 4 │ if sys.argv[0].endswith('.exe'): │
│ 5 │ │ sys.argv[0] = sys.argv[0][:-4] │
│ ❱ 6 │ sys.exit(main()) │
│ 7 │
│ │
│ C:\Users\vadim\anaconda3\envs\heretic\Lib\site-packages\heretic\main.py:592 in main │
│ │
│ 589 │ install() │
│ 590 │ │
│ 591 │ try: │
│ ❱ 592 │ │ run() │
│ 593 │ except BaseException as error: │
│ 594 │ │ # Transformers appears to handle KeyboardInterrupt (or BaseException) │
│ 595 │ │ # internally in some places, which can re-raise a different error in the handler │
│ │
│ C:\Users\vadim\anaconda3\envs\heretic\Lib\site-packages\heretic\main.py:379 in run │
│ │
│ 376 │ ) │
│ 377 │ │
│ 378 │ try: │
│ ❱ 379 │ │ study.optimize(objective_wrapper, n_trials=settings.n_trials) │
│ 380 │ except KeyboardInterrupt: │
│ 381 │ │ # This additional handler takes care of the small chance that KeyboardInterrupt │
│ 382 │ │ # is raised just between trials, which wouldn't be caught by the handler │
│ │
│ C:\Users\vadim\anaconda3\envs\heretic\Lib\site-packages\optuna\study\study.py:490 in optimize │
│ │
│ 487 │ │ │ RuntimeError: │
│ 488 │ │ │ │ If nested invocation of this method occurs. │
│ 489 │ │ """ │
│ ❱ 490 │ │ _optimize( │
│ 491 │ │ │ study=self, │
│ 492 │ │ │ func=func, │
│ 493 │ │ │ n_trials=n_trials, │
│ │
│ C:\Users\vadim\anaconda3\envs\heretic\Lib\site-packages\optuna\study_optimize.py:67 in │
│ _optimize │
│ │
│ 64 │ │
│ 65 │ try: │
│ 66 │ │ if n_jobs == 1: │
│ ❱ 67 │ │ │ _optimize_sequential( │
│ 68 │ │ │ │ study, │
│ 69 │ │ │ │ func, │
│ 70 │ │ │ │ n_trials, │
│ │
│ C:\Users\vadim\anaconda3\envs\heretic\Lib\site-packages\optuna\study_optimize.py:164 in │
│ _optimize_sequential │
│ │
│ 161 │ │ │ │ break │
│ 162 │ │ │
│ 163 │ │ try: │
│ ❱ 164 │ │ │ frozen_trial_id = _run_trial(study, func, catch) │
│ 165 │ │ finally: │
│ 166 │ │ │ # The following line mitigates memory problems that can be occurred in some │
│ 167 │ │ │ # environments (e.g., services that use computing containers such as GitHub │
│ │
│ C:\Users\vadim\anaconda3\envs\heretic\Lib\site-packages\optuna\study_optimize.py:262 in │
│ _run_trial │
│ │
│ 259 │ │ and func_err is not None │
│ 260 │ │ and not isinstance(func_err, catch) │
│ 261 │ ): │
│ ❱ 262 │ │ raise func_err │
│ 263 │ return trial._trial_id │
│ 264 │
│ 265 │
│ │
│ C:\Users\vadim\anaconda3\envs\heretic\Lib\site-packages\optuna\study_optimize.py:205 in │
│ _run_trial │
│ │
│ 202 │ │
│ 203 │ with get_heartbeat_thread(trial._trial_id, study.storage): │
│ 204 │ │ try: │
│ ❱ 205 │ │ │ value_or_values = func(trial) │
│ 206 │ │ except exceptions.TrialPruned as e: │
│ 207 │ │ │ # TODO(mamu): Handle multi-objective cases. │
│ 208 │ │ │ state = TrialState.PRUNED │
│ │
│ C:\Users\vadim\anaconda3\envs\heretic\Lib\site-packages\heretic\main.py:363 in objective_wrapper │
│ │
│ 360 │ │
│ 361 │ def objective_wrapper(trial: Trial) -> tuple[float, float]: │
│ 362 │ │ try: │
│ ❱ 363 │ │ │ return objective(trial) │
│ 364 │ │ except KeyboardInterrupt: │
│ 365 │ │ │ # Stop the study gracefully on Ctrl+C. │
│ 366 │ │ │ trial.study.stop() │
│ │
│ C:\Users\vadim\anaconda3\envs\heretic\Lib\site-packages\heretic\main.py:341 in objective │
│ │
│ 338 │ │ print("* Reloading model...") │
│ 339 │ │ model.reload_model() │
│ 340 │ │ print("* Abliterating...") │
│ ❱ 341 │ │ model.abliterate(refusal_directions, direction_index, parameters) │
│ 342 │ │ print("* Evaluating...") │
│ 343 │ │ score, kl_divergence, refusals = evaluator.get_score() │
│ 344 │
│ │
│ C:\Users\vadim\anaconda3\envs\heretic\Lib\site-packages\heretic\model.py:239 in abliterate │
│ │
│ 236 │ │ │ │ │ # Ensure projector is on the same device as the matrix for multi-GPU │
│ 237 │ │ │ │ │ device_projector = projector.to(matrix.device) │
│ 238 │ │ │ │ │ # In-place subtraction is safe as we're not using Autograd. │
│ ❱ 239 │ │ │ │ │ matrix.sub(weight * (device_projector @ matrix)) │
│ 240 │ │
│ 241 │ def get_chat(self, prompt: str) -> list[dict[str, str]]: │
│ 242 │ │ return [ │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
RuntimeError: mat1 and mat2 shapes cannot be multiplied (8192x8192 and 100663296x1)
@rigin commented on GitHub (Dec 2, 2025):
About hardware and software.
RAM: 64 GB.
GPU 0: NVIDIA GeForce RTX 5060 Ti 16GB
GPU 1: NVIDIA GeForce RTX 5060 Ti 16GB
GPU 2: NVIDIA GeForce RTX 4060 Ti 16GB
Software installation:
@Vinay-Umrethe commented on GitHub (Dec 2, 2025):
The error is caused by a matrix shape mismatch (8192x8192 and 100663296x1).
code is trying to perform math operation matrix multiplication on the model's weights, but specific 4-bit quantized format of the model you suggested is incompatible with that operation.
The model loaded fine, but the custom operation in script failed because it doesn't know how to handle the compressed weight format.
I suggest you can check https://github.com/p-e-w/heretic/pull/60 PR A user has made some changes to support such quantized models
Go to their Repo which is not merged yet https://github.com/accemlcc/heretic-lora/tree/master and built a .whl install it for directly OR you clone it and run:
another user reported it likely worked for him...
@Vinay-Umrethe commented on GitHub (Dec 2, 2025):
you might do everything the same just replace the repo url wih the PR that supports bitsandbytes quants to ablate models using heretic
like:
@rigin commented on GitHub (Dec 2, 2025):
I understand that this fork creates a lora model, which then needs to be combined with the original model?
@Vinay-Umrethe commented on GitHub (Dec 2, 2025):
So I built the wheel of that fork, and tested with a small model looks like it got loaded, but got a error:
Which Means The User's Fork Has Issues In It.
Soultion I can suggest:
let's try doing it with before this error commit has be done by:
I'll give it a try and tell if it worked
@Vinay-Umrethe commented on GitHub (Dec 2, 2025):
Ok so it did worked and it saves the LoRA Adapters only which you need to merge into model
heretic_llm-1.0.1.tar.gz
this the one i built and used.
@rigin commented on GitHub (Dec 2, 2025):
Copied it from your archive to the program folder. The error seems to have disappeared. Thank you.
@rigin commented on GitHub (Dec 3, 2025):
I performed abliteration of the model, but it practically did not work. Refusals: 59/118, KL divergence: 0.26.
The dataset has been finalized by me. Added several lines to harmful_behaviors in both train-00000-of-00001 and test-00000-of-00001.
Manual testing showed that the censorship has not been lifted. The size of the Lora is 24 MB.
@Vinay-Umrethe commented on GitHub (Dec 3, 2025):
That explains the reason why it didn't worked out as your Injected LoRA Adapters are so small it didn't touched model's brain much as expected. Main part is all frozen
The solution is to Increase your LoRA rank
r=1024and lora_alpha=1024This simply means the amount of percentage that will be affected. I normally in use
randalphaequal in fine-tuning tasks which works well.With this more percentage size of adapters would increase highly but results would be better
You can increase or decrease these numbers based on your VRAM consumption i would suggest use powers of 2 like 512,1024,2048, etc
@accemlcc commented on GitHub (Dec 9, 2025):
Thanks for the testing and the feedback!
Fixed: NameError: 'projector': You were right, this was a regression in the PR branch. I've pushed a fix – the projector variable is no longer used in the code path (replaced by an optimized rank-1 update) and is now only present in comments.
LoRA Rank: Theoretically, r=1 is sufficient for this task. Abliteration is mathematically a rank-1 update (subtracting a single vector outer product per layer). Increasing the rank shouldn't improve the quality of the ablation itself, only memory usage.
Efficacy / Censorship not lifted: This is likely unrelated to LoRA rank. There is a known regression in heretic regarding Tokenizer padding that breaks KL divergence computation for some models (causing it to be always 0, which prevents the optimizer from working). Please check Issue #75. It is highly likely that the fix described there (commenting out the tokenizer padding fallback in src/heretic/model.py) will resolve the issue and make the ablation effective again.
@Vinay-Umrethe commented on GitHub (Dec 9, 2025):
Thanks this was a useful info. doing great work @accemlcc
@p-e-w commented on GitHub (Oct 12, 2026):
Closing as this appears to be fixed.