Skip to content

Conversation

@tamarPal
Copy link
Contributor

@tamarPal tamarPal commented Nov 4, 2025

Add safety checks to prevent catastrophic data loss when users accidentally specify the same file for both input and output in llama-quantize.

Changes:

  • Add same_file() function to detect identical files (including symlinks/hardlinks)
  • Block quantization when input==output without --inplace flag
  • Add --inplace flag for safe in-place quantization using temp file + atomic rename
  • Add --overwrite flag to allow overwriting existing files
  • Add comprehensive test suite (test_quantize_safety.sh)

Before this fix: input file would be truncated immediately, causing SIGBUS and data loss
After this fix: clear error message with solutions, or safe in-place operation with --inplace

Fixes #12753

…ml-org#12753)

Add safety checks to prevent catastrophic data loss when users accidentally
specify the same file for both input and output in llama-quantize.

Changes:
- Add same_file() function to detect identical files (including symlinks/hardlinks)
- Block quantization when input==output without --inplace flag
- Add --inplace flag for safe in-place quantization using temp file + atomic rename
- Add --overwrite flag to allow overwriting existing files
- Add comprehensive test suite (test_quantize_safety.sh)

Before this fix: input file would be truncated immediately, causing SIGBUS and data loss
After this fix: clear error message with solutions, or safe in-place operation with --inplace

Fixes ggml-org#12753
@tamarPal tamarPal requested a review from ggerganov as a code owner November 4, 2025 13:11
@tamarPal
Copy link
Contributor Author

tamarPal commented Nov 4, 2025

@slaren @m18coppola
This PR fixes the issue where the input and output file paths were identical during quantization, which could lead to file truncation and SIGBUS errors.
I’ve added proper validation and a safe handling path for this case.
The fix ensures that:

  • The tool now prevents in-place overwrite unless --inplace is explicitly set.

  • Clear error messages are shown to the user in such cases.

Would appreciate a quick review and confirmation that this approach aligns with the project’s intended behavior.
Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Misc. bug: llama-quantize clobbers input file + crashes when output file matches

1 participant