Skip to content

Conversation

@Anri-Lombard
Copy link

Summary

  • Add check to prevent quantizing when input and output files are the same
  • Uses std::filesystem::equivalent() to handle path variations (e.g., ./file vs file)
  • Prevents file corruption caused by mmap reading from a file being simultaneously written

Test

# Before fix: file gets corrupted (19MB -> 727KB)
llama-quantize model.gguf model.gguf Q4_0

# After fix: clean error message, file preserved
main: error: input and output files are the same: 'model.gguf'

Fixes #12753

Check if input and output files are the same before quantizing to prevent
file corruption when mmap reads from a file being written to.

Fixes ggml-org#12753
@Anri-Lombard Anri-Lombard force-pushed the fix/quantize-same-file-check branch from 0f7e99c to 76e12d6 Compare December 30, 2025 03:18
@Anri-Lombard
Copy link
Author

Anri-Lombard commented Dec 30, 2025

Updated to use the error_code overload as suggested. Thanks @danbev

@Anri-Lombard Anri-Lombard requested a review from danbev December 30, 2025 04:16
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

2 participants