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 #535] [v2.0.0.dev0] Crash in non-interactive mode after optimization completes (EOFError from prompt_toolkit) #230

Open
opened 2026-11-01 04:18:51 +07:00 by bsakaguchi · 2 comments
Owner

Originally created by @instax-dutta on GitHub (Oct 29, 2026).
Original GitHub issue: https://github.com/p-e-w/heretic/issues/535

[v2.0.0.dev0] Crash in non-interactive mode after optimization completes (EOFError from prompt_toolkit)

Summary

Heretic v2.0.0.dev0 crashes with an EOFError/PermissionError from prompt_toolkit when running in non-interactive environments (e.g., nohup, script, CI, piped stdin) after the Optuna optimization finishes. This prevents saving the abliterated model, uploading to HuggingFace, or continuing the post-optimization workflow without a TTY.

Environment

  • Heretic version: heretic-llm-2.0.0.dev0 (installed from git+https://github.com/p-e-w/heretic.git)
  • Python: 3.11
  • PyTorch: 2.6.0+cu124
  • transformers: 5.22.0, peft: 0.21.2, huggingface-hub: 1.33.0, datasets: 5.1.0
  • OS: Linux (Debian/Ubuntu)
  • Hardware: 2x Tesla T4 GPUs
  • Model tested: LiquidAI/LFM2.5-230M

Reproduction

  1. Install v2.0 dependencies as specified (had some dependency conflicts on initial attempt; see notes below)
  2. Run Heretic with trials in non-interactive mode, e.g.:
nohup timeout 90000 heretic --model LiquidAI/LFM2.5-230M > run.log 2>&1 &
# or
echo continue | heretic --model LiquidAI/LFM2.5-230M --n-additional-trials 50 --checkpoint-action continue
# or
script -qec "..." /dev/null
  1. Optimization completes successfully (all trials finish, Pareto front computed)
  2. Heretic attempts to show interactive menu to select trial / save / upload / chat / benchmark
  3. Crashes with EOFError

Observed Behavior

After "Optimization finished!" and displaying Pareto optimal trials, Heretic tries to prompt interactively and fails:

Optimization finished!

The following trials resulted in Pareto optimal combinations of the optimization
objectives. After selecting a trial, you will be able to save the model, upload 
it to Hugging Face, chat with it to test how well it works, or run standard 
benchmarks on it. You can return to this menu later to select a different trial.

Warning: Input is not a terminal (fd=0).
...
EOFError

Full traceback (from logs):

File "/root/heretic-env/lib/python3.11/site-packages/prompt_toolkit/application/application.py", line 1000, in run
    return asyncio.run(coro)
...
File "/root/heretic-env/lib/python3.11/site-packages/prompt_toolkit/input/vt100.py", line 180, in _attached_input
    raise EOFError
EOFError

See attached logs: run3_20261030_032306.log, additional_cont_*.log etc. in test artifacts.

Expected Behavior

  • When run in non-interactive environments (no TTY), Heretic should either:
    1. Auto-select a sensible default trial (e.g., best by some criterion from Pareto front) and proceed with a default action, or
    2. Respect command-line flags like --trial-index, --model-action, --save-directory without prompting, or
    3. Exit gracefully with a clear error message instructing the user to provide the necessary flags
  • Add support for --non-interactive/--yes flags or detect non-TTY (sys.stdin.isatty())

Additional Context

Dependency installation issues (for v2.0 testing)

The v2.0 pre-release has strict dependency requirements that caused conflicts during installation:

  • Required: transformers[torch]~=5.18, peft~=0.21, huggingface-hub~=1.33, datasets~=5.0
  • These conflict with older PyTorch versions; needed PyTorch 2.6.0+cu124 for compatibility
  • Also conflicts with kernels package and some transitive deps
  • Had to do multiple install attempts to get a working environment. This made testing the pre-release more difficult than expected.

Testing results (for context)

We ran 450+ trials across 3 runs testing LiquidAI/LFM2.5-230M. Best configuration found: Trial 82 with KL=0.038817, Refusals=8/100 which outperforms the user's v1.4.0 baseline (KL 0.0548, 10/100 refusals). The optimization/search functionality works well; the issue is purely the post-optimization interactive flow in non-TTY environments.

Suggested Fix

In heretic/main.py around the trial selection/saving logic, check if running interactively (sys.stdin.isatty() and/or sys.stdout.isatty()). If not interactive and required parameters aren't provided, either:

  • Use sensible defaults (e.g., select trial 0 from sorted Pareto front, or skip to a safe exit)
  • Make the prompts respect --trial-index, --model-action, --save-directory flags fully
  • Provide clear error messages about missing required flags for non-interactive use

This would make the v2.0 pre-release testable as instructed in the announcement.

Originally created by @instax-dutta on GitHub (Oct 29, 2026). Original GitHub issue: https://github.com/p-e-w/heretic/issues/535 # [v2.0.0.dev0] Crash in non-interactive mode after optimization completes (EOFError from prompt_toolkit) ## Summary Heretic v2.0.0.dev0 crashes with an `EOFError`/`PermissionError` from `prompt_toolkit` when running in non-interactive environments (e.g., `nohup`, `script`, CI, piped stdin) after the Optuna optimization finishes. This prevents saving the abliterated model, uploading to HuggingFace, or continuing the post-optimization workflow without a TTY. ## Environment - Heretic version: `heretic-llm-2.0.0.dev0` (installed from `git+https://github.com/p-e-w/heretic.git`) - Python: 3.11 - PyTorch: 2.6.0+cu124 - transformers: 5.22.0, peft: 0.21.2, huggingface-hub: 1.33.0, datasets: 5.1.0 - OS: Linux (Debian/Ubuntu) - Hardware: 2x Tesla T4 GPUs - Model tested: `LiquidAI/LFM2.5-230M` ## Reproduction 1. Install v2.0 dependencies as specified (had some dependency conflicts on initial attempt; see notes below) 2. Run Heretic with trials in non-interactive mode, e.g.: ```bash nohup timeout 90000 heretic --model LiquidAI/LFM2.5-230M > run.log 2>&1 & # or echo continue | heretic --model LiquidAI/LFM2.5-230M --n-additional-trials 50 --checkpoint-action continue # or script -qec "..." /dev/null ``` 3. Optimization completes successfully (all trials finish, Pareto front computed) 4. Heretic attempts to show interactive menu to select trial / save / upload / chat / benchmark 5. Crashes with EOFError ## Observed Behavior After "Optimization finished!" and displaying Pareto optimal trials, Heretic tries to prompt interactively and fails: ``` Optimization finished! The following trials resulted in Pareto optimal combinations of the optimization objectives. After selecting a trial, you will be able to save the model, upload it to Hugging Face, chat with it to test how well it works, or run standard benchmarks on it. You can return to this menu later to select a different trial. Warning: Input is not a terminal (fd=0). ... EOFError ``` Full traceback (from logs): ``` File "/root/heretic-env/lib/python3.11/site-packages/prompt_toolkit/application/application.py", line 1000, in run return asyncio.run(coro) ... File "/root/heretic-env/lib/python3.11/site-packages/prompt_toolkit/input/vt100.py", line 180, in _attached_input raise EOFError EOFError ``` See attached logs: `run3_20261030_032306.log`, `additional_cont_*.log` etc. in test artifacts. ## Expected Behavior - When run in non-interactive environments (no TTY), Heretic should either: 1. Auto-select a sensible default trial (e.g., best by some criterion from Pareto front) and proceed with a default action, or 2. Respect command-line flags like `--trial-index`, `--model-action`, `--save-directory` without prompting, or 3. Exit gracefully with a clear error message instructing the user to provide the necessary flags - Add support for `--non-interactive`/`--yes` flags or detect non-TTY (`sys.stdin.isatty()`) ## Additional Context ### Dependency installation issues (for v2.0 testing) The v2.0 pre-release has strict dependency requirements that caused conflicts during installation: - Required: `transformers[torch]~=5.18`, `peft~=0.21`, `huggingface-hub~=1.33`, `datasets~=5.0` - These conflict with older PyTorch versions; needed PyTorch 2.6.0+cu124 for compatibility - Also conflicts with `kernels` package and some transitive deps - Had to do multiple install attempts to get a working environment. This made testing the pre-release more difficult than expected. ### Testing results (for context) We ran 450+ trials across 3 runs testing `LiquidAI/LFM2.5-230M`. Best configuration found: **Trial 82 with KL=0.038817, Refusals=8/100** which outperforms the user's v1.4.0 baseline (KL 0.0548, 10/100 refusals). The optimization/search functionality works well; the issue is purely the post-optimization interactive flow in non-TTY environments. ## Suggested Fix In `heretic/main.py` around the trial selection/saving logic, check if running interactively (`sys.stdin.isatty()` and/or `sys.stdout.isatty()`). If not interactive and required parameters aren't provided, either: - Use sensible defaults (e.g., select trial 0 from sorted Pareto front, or skip to a safe exit) - Make the prompts respect `--trial-index`, `--model-action`, `--save-directory` flags fully - Provide clear error messages about missing required flags for non-interactive use This would make the v2.0 pre-release testable as instructed in the announcement.
Author
Owner

@p-e-w commented on GitHub (Oct 30, 2026):

Make the prompts respect --trial-index, --model-action, --save-directory flags fully

Please elaborate. How are they currently not respected "fully"?

<!-- gh-comment-id:6522892187 --> @p-e-w commented on GitHub (Oct 30, 2026): > Make the prompts respect --trial-index, --model-action, --save-directory flags fully Please elaborate. How are they currently not respected "fully"?
Author
Owner

@instax-dutta commented on GitHub (Oct 30, 2026):

We hit this in scripted/headless runs with stdin closed (e.g. timeout ... heretic ... |& tee log or when stdin is /dev/null). In that environment, stdin.isatty() is False - questionary/prompt_toolkit can still try to prompt in the post-optimization flow and raise EOFError. Even if flags like --trial-index, --model-action, --save-directory/--upload-repo-id are passed, in our case it crashed after optimization when trying to select a trial/action.

The fix is to detect non-TTY/EOF early and fall back to CLI-provided values (or sensible defaults like first Pareto trial + auto-select save/upload based on flags) instead of letting the prompt raise EOFError. PR #537 does this defensively. Happy to adjust if there's a specific pattern the tests expect.

<!-- gh-comment-id:6529720023 --> @instax-dutta commented on GitHub (Oct 30, 2026): We hit this in scripted/headless runs with stdin closed (e.g. `timeout ... heretic ... |& tee log` or when stdin is `/dev/null`). In that environment, `stdin.isatty()` is False - questionary/prompt_toolkit can still try to prompt in the post-optimization flow and raise `EOFError`. Even if flags like `--trial-index`, `--model-action`, `--save-directory`/`--upload-repo-id` are passed, in our case it crashed after optimization when trying to select a trial/action. The fix is to detect non-TTY/EOF early and fall back to CLI-provided values (or sensible defaults like first Pareto trial + auto-select save/upload based on flags) instead of letting the prompt raise EOFError. PR #537 does this defensively. Happy to adjust if there's a specific pattern the tests expect.
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#230
No description provided.