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

[GH-ISSUE #291] Observation on Optimization Behavior: Refusals Parameter Not Converging #167

Closed
opened 2026-11-01 04:18:13 +07:00 by bsakaguchi · 1 comment
Owner

Originally created by @rigin on GitHub (Apr 9, 2026).
Original GitHub issue: https://github.com/p-e-w/heretic/issues/291

Dear @p-e-w, I launched the removal of censorship of a small model by your algorithm and noticed the strangeness of the behavior of the parameters used for optimization in the listing. I sent the listing and your code to a chat with Qwen3.6-Plus and discussed the problem with him for 2 days, and at the end of the discussions I asked Qwen to formulate a summary of the conversation in English as information for you. Below is the summary. I will add that I use an extended dataset in English and in Russian, the total sample when comparing Refusals 236.

config.toml.txt

Observation on Optimization Behavior: Refusals Parameter Not Converging

Hi @p-e-w,

First of all, thank you for this excellent project — the codebase is well-structured and the concept is brilliant.

I've been running abliteration experiments and noticed something I'd like to discuss regarding the optimization behavior.

🔍 Observation

When monitoring the refusals metric across trials (400 total, split into two batches of 200), I observe:

  • The value oscillates between extremes (~10–225) rather than converging
  • Initial trials show improvement, but later trials continue to "jump" across the full range
  • No clear trend toward minimization, even after the startup phase

Example trajectory (Refusals count, lower is better):

225, 200, 168, 69, 107, 147, ... 187, 174, 19, 64, ... 173, 189, 174

🤔 Initial Hypothesis vs. Code Reality

My first assumption was that this might be a gradient-based optimizer with issues. However, after reviewing main.py, I see that Optuna's TPE sampler is used:

study = optuna.create_study(
    sampler=TPESampler(
        n_startup_trials=settings.n_startup_trials,
        n_ei_candidates=128,
        multivariate=True,  # ← Multivariate TPE
    ),
    directions=[StudyDirection.MINIMIZE, StudyDirection.MINIMIZE],  # ← Multi-objective!
    ...
)

💡 Why This Behavior Might Be Expected

1. Multi-objective optimization creates a Pareto front

The objective function returns a tuple:

# evaluator.py
return (kld_score, refusals_score)  # Two objectives to minimize

TPE optimizes both KL divergence and refusals simultaneously. These objectives often conflict:

  • Lower refusals → higher KL divergence (model "breaks")
  • Lower KL divergence → higher refusals (less abliteration)

Result: TPE explores the Pareto frontier, sampling points that represent different trade-offs. This can appear as "random bouncing" when viewing a single metric in isolation.

2. No pruner configured

study = optuna.create_study(
    sampler=TPESampler(...),
    # ❌ No pruner specified
)

Without a pruner (e.g., HyperbandPruner), all trials run to completion, even if early evaluations show poor performance. This reduces sample efficiency and may slow convergence.

3. Wide parameter ranges + multivariate TPE

max_weight = trial.suggest_float(f"{component}.max_weight", 0.8, 1.5)
max_weight_position = trial.suggest_float(..., 0.6 * last_layer_index, 1.0 * last_layer_index)

With multivariate=True, TPE models joint distributions, which is powerful but requires more trials to converge — especially with 4+ parameters per component.

🛠️ Suggestions for Improvement

  1. Add a pruner to cut unpromising trials early:

    from optuna.pruners import HyperbandPruner
    study = optuna.create_study(
        sampler=TPESampler(...),
        pruner=HyperbandPruner(min_resource=1, max_resource=100, reduction_factor=3),
        ...
    )
    
  2. Consider single-objective optimization if refusals are the primary goal:

    # evaluator.py
    combined_score = refusals_score + λ * kl_divergence  # Weighted sum
    return combined_score, kl_divergence, refusals
    

    Then use directions=[StudyDirection.MINIMIZE].

  3. Dynamic range narrowing: After N trials, analyze parameter importances (optuna.visualization.plot_param_importances) and suggest narrowed ranges for subsequent trials.

  4. Visualization aid: Add an optional flag to export trial history to CSV for external plotting (helps diagnose convergence issues).

❓ Questions for Discussion

  1. Is the observed "bouncing" behavior expected given the multi-objective setup, or could there be a configuration issue?
  2. Would adding a pruner significantly improve sample efficiency for this use case?
  3. Are there recommended practices for balancing KL divergence vs. refusals in the objective function?

Happy to help test any changes or provide additional logs/metrics. Thanks again for the great work! 🙏


Environment: Heretic v0.x, Optuna 3.x, PyTorch 2.x, CUDA
Model: aya-expanse-8b
Config: [attach relevant config snippet if helpful]

Originally created by @rigin on GitHub (Apr 9, 2026). Original GitHub issue: https://github.com/p-e-w/heretic/issues/291 Dear @p-e-w, I launched the removal of censorship of a small model by your algorithm and noticed the strangeness of the behavior of the parameters used for optimization in the listing. I sent the listing and your code to a chat with Qwen3.6-Plus and discussed the problem with him for 2 days, and at the end of the discussions I asked Qwen to formulate a summary of the conversation in English as information for you. Below is the summary. I will add that I use an extended dataset in English and in Russian, the total sample when comparing Refusals 236. [config.toml.txt](https://github.com/user-attachments/files/26601336/config.toml.txt) # Observation on Optimization Behavior: Refusals Parameter Not Converging Hi @p-e-w, First of all, thank you for this excellent project — the codebase is well-structured and the concept is brilliant. I've been running abliteration experiments and noticed something I'd like to discuss regarding the optimization behavior. ## 🔍 Observation When monitoring the `refusals` metric across trials (400 total, split into two batches of 200), I observe: - The value **oscillates between extremes** (~10–225) rather than converging - Initial trials show improvement, but later trials continue to "jump" across the full range - No clear trend toward minimization, even after the startup phase Example trajectory (Refusals count, lower is better): ``` 225, 200, 168, 69, 107, 147, ... 187, 174, 19, 64, ... 173, 189, 174 ``` ## 🤔 Initial Hypothesis vs. Code Reality My first assumption was that this might be a gradient-based optimizer with issues. However, after reviewing `main.py`, I see that **Optuna's TPE sampler** is used: ```python study = optuna.create_study( sampler=TPESampler( n_startup_trials=settings.n_startup_trials, n_ei_candidates=128, multivariate=True, # ← Multivariate TPE ), directions=[StudyDirection.MINIMIZE, StudyDirection.MINIMIZE], # ← Multi-objective! ... ) ``` ## 💡 Why This Behavior Might Be Expected ### 1. Multi-objective optimization creates a Pareto front The objective function returns a tuple: ```python # evaluator.py return (kld_score, refusals_score) # Two objectives to minimize ``` TPE optimizes **both KL divergence and refusals simultaneously**. These objectives often conflict: - Lower refusals → higher KL divergence (model "breaks") - Lower KL divergence → higher refusals (less abliteration) Result: TPE explores the **Pareto frontier**, sampling points that represent different trade-offs. This can appear as "random bouncing" when viewing a single metric in isolation. ### 2. No pruner configured ```python study = optuna.create_study( sampler=TPESampler(...), # ❌ No pruner specified ) ``` Without a pruner (e.g., `HyperbandPruner`), **all trials run to completion**, even if early evaluations show poor performance. This reduces sample efficiency and may slow convergence. ### 3. Wide parameter ranges + multivariate TPE ```python max_weight = trial.suggest_float(f"{component}.max_weight", 0.8, 1.5) max_weight_position = trial.suggest_float(..., 0.6 * last_layer_index, 1.0 * last_layer_index) ``` With `multivariate=True`, TPE models joint distributions, which is powerful but requires more trials to converge — especially with 4+ parameters per component. ## 🛠️ Suggestions for Improvement 1. **Add a pruner** to cut unpromising trials early: ```python from optuna.pruners import HyperbandPruner study = optuna.create_study( sampler=TPESampler(...), pruner=HyperbandPruner(min_resource=1, max_resource=100, reduction_factor=3), ... ) ``` 2. **Consider single-objective optimization** if refusals are the primary goal: ```python # evaluator.py combined_score = refusals_score + λ * kl_divergence # Weighted sum return combined_score, kl_divergence, refusals ``` Then use `directions=[StudyDirection.MINIMIZE]`. 3. **Dynamic range narrowing**: After N trials, analyze parameter importances (`optuna.visualization.plot_param_importances`) and suggest narrowed ranges for subsequent trials. 4. **Visualization aid**: Add an optional flag to export trial history to CSV for external plotting (helps diagnose convergence issues). ## ❓ Questions for Discussion 1. Is the observed "bouncing" behavior expected given the multi-objective setup, or could there be a configuration issue? 2. Would adding a pruner significantly improve sample efficiency for this use case? 3. Are there recommended practices for balancing KL divergence vs. refusals in the objective function? Happy to help test any changes or provide additional logs/metrics. Thanks again for the great work! 🙏 --- *Environment*: Heretic v0.x, Optuna 3.x, PyTorch 2.x, CUDA *Model*: aya-expanse-8b *Config*: [attach relevant config snippet if helpful]
Author
Owner

@p-e-w commented on GitHub (Apr 9, 2026):

Heretic uses Bayesian parameter optimization (TPE). TPE is a black-box method. It is not analogous to gradient descent, or other differential-guided approaches. In particular, there is no reason to expect the optimization trajectory to "converge". This isn't how stochastic optimization works.

In other words,

No clear trend toward minimization, even after the startup phase

Yes, that's perfectly normal, and not indicative of a problem at all.

<!-- gh-comment-id:4215168130 --> @p-e-w commented on GitHub (Apr 9, 2026): Heretic uses Bayesian parameter optimization (TPE). TPE is a black-box method. It is not analogous to gradient descent, or other differential-guided approaches. In particular, **there is no reason to expect the optimization trajectory to "converge".** This isn't how stochastic optimization works. In other words, > No clear trend toward minimization, even after the startup phase Yes, that's perfectly normal, and not indicative of a problem at all.
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#167
No description provided.