Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add detailed error messaging for reading/writing of model files. #39

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions cformers/cpp/quantize_bloom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <fstream>
#include <map>
#include <string>
#include <system_error>
#include <vector>
#include <regex>

Expand Down Expand Up @@ -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;
}

Expand Down
7 changes: 5 additions & 2 deletions cformers/cpp/quantize_gpt2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <fstream>
#include <map>
#include <string>
#include <system_error>
#include <vector>
#include <regex>

Expand Down Expand Up @@ -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;
}

Expand Down
7 changes: 5 additions & 2 deletions cformers/cpp/quantize_gptj.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <fstream>
#include <map>
#include <string>
#include <system_error>
#include <vector>
#include <regex>

Expand Down Expand Up @@ -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;
}

Expand Down
7 changes: 5 additions & 2 deletions cformers/cpp/quantize_gptneox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <fstream>
#include <map>
#include <string>
#include <system_error>
#include <vector>
#include <regex>

Expand Down Expand Up @@ -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;
}

Expand Down