From a2379f818e7aa8dde61c0cde856ae780c1171ba5 Mon Sep 17 00:00:00 2001 From: Anup Ghatage Date: Sat, 15 Apr 2023 12:31:26 -0700 Subject: [PATCH] Add detailed error messaging for reading/writing of model files. --- cformers/cpp/quantize_bloom.cpp | 7 +++++-- cformers/cpp/quantize_gpt2.cpp | 7 +++++-- cformers/cpp/quantize_gptj.cpp | 7 +++++-- cformers/cpp/quantize_gptneox.cpp | 7 +++++-- 4 files changed, 20 insertions(+), 8 deletions(-) diff --git a/cformers/cpp/quantize_bloom.cpp b/cformers/cpp/quantize_bloom.cpp index 0fb431a..3761989 100644 --- a/cformers/cpp/quantize_bloom.cpp +++ b/cformers/cpp/quantize_bloom.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include #include @@ -48,13 +49,15 @@ bool bloom_model_quantize(const std::string & fname_inp, const std::string & fna auto finp = std::ifstream(fname_inp, std::ios::binary); if (!finp) { - fprintf(stderr, "%s: failed to open '%s' for reading\n", __func__, fname_inp.c_str()); + std::error_code ec(errno, std::generic_category()); + fprintf(stderr, "%s: failed to open '%s' for reading: %s\n", __func__, fname_inp.c_str(), ec.message().c_str()); return false; } auto fout = std::ofstream(fname_out, std::ios::binary); if (!fout) { - fprintf(stderr, "%s: failed to open '%s' for writing\n", __func__, fname_out.c_str()); + std::error_code ec(errno, std::generic_category()); + fprintf(stderr, "%s: failed to open '%s' for writing: %s\n", __func__, fname_out.c_str(), ec.message().c_str()); return false; } diff --git a/cformers/cpp/quantize_gpt2.cpp b/cformers/cpp/quantize_gpt2.cpp index 6a76581..126d699 100644 --- a/cformers/cpp/quantize_gpt2.cpp +++ b/cformers/cpp/quantize_gpt2.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include #include @@ -47,13 +48,15 @@ bool gpt2_model_quantize(const std::string & fname_inp, const std::string & fnam auto finp = std::ifstream(fname_inp, std::ios::binary); if (!finp) { - fprintf(stderr, "%s: failed to open '%s' for reading\n", __func__, fname_inp.c_str()); + std::error_code ec(errno, std::generic_category()); + fprintf(stderr, "%s: failed to open '%s' for reading: %s\n", __func__, fname_inp.c_str(), ec.message().c_str()); return false; } auto fout = std::ofstream(fname_out, std::ios::binary); if (!fout) { - fprintf(stderr, "%s: failed to open '%s' for writing\n", __func__, fname_out.c_str()); + std::error_code ec(errno, std::generic_category()); + fprintf(stderr, "%s: failed to open '%s' for writing: %s\n", __func__, fname_out.c_str(), ec.message().c_str()); return false; } diff --git a/cformers/cpp/quantize_gptj.cpp b/cformers/cpp/quantize_gptj.cpp index 6a82319..49b60fa 100644 --- a/cformers/cpp/quantize_gptj.cpp +++ b/cformers/cpp/quantize_gptj.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include #include @@ -47,13 +48,15 @@ bool gptj_model_quantize(const std::string & fname_inp, const std::string & fnam auto finp = std::ifstream(fname_inp, std::ios::binary); if (!finp) { - fprintf(stderr, "%s: failed to open '%s' for reading\n", __func__, fname_inp.c_str()); + std::error_code ec(errno, std::generic_category()); + fprintf(stderr, "%s: failed to open '%s' for reading: %s\n", __func__, fname_inp.c_str(), ec.message().c_str()); return false; } auto fout = std::ofstream(fname_out, std::ios::binary); if (!fout) { - fprintf(stderr, "%s: failed to open '%s' for writing\n", __func__, fname_out.c_str()); + std::error_code ec(errno, std::generic_category()); + fprintf(stderr, "%s: failed to open '%s' for writing: %s\n", __func__, fname_out.c_str(), ec.message().c_str()); return false; } diff --git a/cformers/cpp/quantize_gptneox.cpp b/cformers/cpp/quantize_gptneox.cpp index 6c30178..1505a1f 100644 --- a/cformers/cpp/quantize_gptneox.cpp +++ b/cformers/cpp/quantize_gptneox.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include #include @@ -48,13 +49,15 @@ bool gptneox_model_quantize(const std::string & fname_inp, const std::string & f auto finp = std::ifstream(fname_inp, std::ios::binary); if (!finp) { - fprintf(stderr, "%s: failed to open '%s' for reading\n", __func__, fname_inp.c_str()); + std::error_code ec(errno, std::generic_category()); + fprintf(stderr, "%s: failed to open '%s' for reading: %s\n", __func__, fname_inp.c_str(), ec.message().c_str()); return false; } auto fout = std::ofstream(fname_out, std::ios::binary); if (!fout) { - fprintf(stderr, "%s: failed to open '%s' for writing\n", __func__, fname_out.c_str()); + std::error_code ec(errno, std::generic_category()); + fprintf(stderr, "%s: failed to open '%s' for writing: %s\n", __func__, fname_out.c_str(), ec.message().c_str()); return false; }