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

[Good First Issue][Bug]: ov::serialize(model) does not report when file writing fails #23190

Open
mlukasze opened this issue Mar 1, 2024 · 8 comments
Labels
good first issue Good for newcomers no_stale Do not mark as stale

Comments

@mlukasze
Copy link
Contributor

mlukasze commented Mar 1, 2024

Context

The ChatGLM application tries to write modified model into disk:
https://github.com/wenyi5608/openvino.genai/blob/fcadd455b485db5ce1330e487077c99283bb3638/llm/chatglm_cpp/chatglm.cpp#L387

When the disk is full, the ov::serialize fails and file size is smaller than expected. However, it does not show any error message for that.

What needs to be done?

To prepare proper error message to inform user about a problem

Example Pull Requests

No response

Resources

Contact points

@olpipi @praasz

Ticket

CVS-128429

@mlukasze mlukasze added good first issue Good for newcomers no_stale Do not mark as stale labels Mar 1, 2024
@github-project-automation github-project-automation bot moved this to Contributors Needed in Good first issues Mar 1, 2024
@mishra-18
Copy link

mishra-18 commented Mar 2, 2024

.take

Copy link
Contributor

github-actions bot commented Mar 2, 2024

Thank you for looking into this issue! Please let us know if you have any questions or require any help.

@mishra-18
Copy link

Hi
I'm assuming wrapping the ov::serialize block with try-cath will be enough. Should I throw the error caught when it fails, or write my own proper error message?

@mlukasze mlukasze moved this from Contributors Needed to Assigned in Good first issues Mar 4, 2024
@vurusovs
Copy link
Contributor

vurusovs commented Mar 4, 2024

@mishra-18 I propose the problem is that std::ofstream doesn't throw exceptions by default, so try/catch won't help. Let's try to set up std::ofstream with exceptions() method here:

std::ofstream bin_file(m_binPath, std::ios::out | std::ios::binary);
OPENVINO_ASSERT(bin_file, "Can't open bin file: \"" + m_binPath + "\"");
// create xml file
std::ofstream xml_file(m_xmlPath, std::ios::out);
OPENVINO_ASSERT(xml_file, "Can't open xml file: \"" + m_xmlPath + "\"");

@mishra-18
Copy link

mishra-18 commented Mar 4, 2024

Hi @vurusovs, Thanks for taking a look.
Would this work?

try {
    std::ofstream bin_file(m_binPath, std::ios::out | std::ios::binary);
    bin_file.exceptions(std::ofstream::failbit | std::ofstream::badbit);
    OPENVINO_ASSERT(bin_file, "Can't open bin file: \"" + m_binPath + "\"");
   
    // create xml file 
    std::ofstream xml_file(m_xmlPath, std::ios::out);
    xml_file.exceptions(std::ofstream::failbit | std::ofstream::badbit);
    OPENVINO_ASSERT(xml_file, "Can't open xml file: \"" + m_xmlPath + "\"");

    serializeFunc(xml_file, bin_file, model, m_version);
} catch (const std::ofstream::failure& e) {
    // Handle file stream errors
    std::cerr << "Exception opening/writing file. Not Enough Space in disk: " << e.what() << '\n';
    std::remove(m_xmlPath.c_str());
    std::remove(m_binPath.c_str());
    throw; 
} catch (const ov::AssertFailure& e) {
    // Handle other exceptions as before
    std::cerr << "OpenVINO assertion failed: " << e.what() << '\n';
    std.ext::remove(m_xmlPath.c_str());
    std.ext::remove(m_binPath.c_str());
    throw;
}

Also, I think
xml_file.close(); bin_file.close(); weren't necessary (assuming the files are closed anyway once they get out of the scope).

@vurusovs
Copy link
Contributor

vurusovs commented Mar 5, 2024

Hi @vurusovs, Thanks for taking a look. Would this work?

try {
    std::ofstream bin_file(m_binPath, std::ios::out | std::ios::binary);
    bin_file.exceptions(std::ofstream::failbit | std::ofstream::badbit);
    OPENVINO_ASSERT(bin_file, "Can't open bin file: \"" + m_binPath + "\"");
   
    // create xml file 
    std::ofstream xml_file(m_xmlPath, std::ios::out);
    xml_file.exceptions(std::ofstream::failbit | std::ofstream::badbit);
    OPENVINO_ASSERT(xml_file, "Can't open xml file: \"" + m_xmlPath + "\"");

    serializeFunc(xml_file, bin_file, model, m_version);
} catch (const std::ofstream::failure& e) {
    // Handle file stream errors
    std::cerr << "Exception opening/writing file. Not Enough Space in disk: " << e.what() << '\n';
    std::remove(m_xmlPath.c_str());
    std::remove(m_binPath.c_str());
    throw; 
} catch (const ov::AssertFailure& e) {
    // Handle other exceptions as before
    std::cerr << "OpenVINO assertion failed: " << e.what() << '\n';
    std.ext::remove(m_xmlPath.c_str());
    std.ext::remove(m_binPath.c_str());
    throw;
}

Also, I think xml_file.close(); bin_file.close(); weren't necessary (assuming the files are closed anyway once they get out of the scope).

Looks fine! Let's create PR where we will discuss final solution. See you on review 😄

mishra-18 added a commit to mishra-18/openvino that referenced this issue Mar 5, 2024
@mlukasze mlukasze moved this from Assigned to In Review in Good first issues Mar 6, 2024
@mlukasze
Copy link
Contributor Author

mlukasze commented Mar 6, 2024

PR: #23281
Thanks @mishra-18, we will review it soon

@mlukasze mlukasze added this to the 2024.4 milestone Jul 25, 2024
@mlukasze mlukasze removed this from the 2024.4 milestone Oct 17, 2024
@mlukasze mlukasze moved this from In Review to Contributors Needed in Good first issues Dec 5, 2024
@geeky33
Copy link
Contributor

geeky33 commented Jan 19, 2025

@mlukasze
@andrei-kochin hello can you please assign this issue to me?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers no_stale Do not mark as stale
Projects
Status: Contributors Needed
Development

Successfully merging a pull request may close this issue.

4 participants