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

[IE][nGraph] resolve division by zero for FP16 #8676

Merged
merged 10 commits into from
Dec 7, 2021

Conversation

pavel-esir
Copy link
Contributor

@pavel-esir pavel-esir commented Nov 18, 2021

Root cause analysis: In some models patterns x/max(y, eps) and x/(y + eps) are used to prevent division by zero. But usually in FP32 networks eps is such small (e.g. 1e-9, 1e-12, ...) that after casting to FP16 it's collapsed to zero. This can lead to division by zero if x and y happen to be also zero.

Solution: To prevent that in such patterns we change eps to FP16 smallest normalized value (0.0000610.., details in Half_precision_examples) in transformation DivisionByZeroFP16Resolver.

Tickets:
Ticket: CVS-66045, CVS-65735

Code:

  • Comments

Validation:

  • Transformation unit-tests: done
  • Model Optimizer IR Reader check: done for DIEN

@pavel-esir pavel-esir added the enhancement New feature or request label Nov 18, 2021
@pavel-esir pavel-esir added this to the 2022.1 milestone Nov 18, 2021
@pavel-esir pavel-esir requested review from a team, sadolini, achetver, yekruglov, rkazants and GlebKazantaev and removed request for a team November 22, 2021 20:51
@pavel-esir pavel-esir marked this pull request as ready for review November 22, 2021 20:53
@pavel-esir pavel-esir requested review from a team November 22, 2021 20:53
Copy link
Contributor

@rkazants rkazants left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do like the solution

@pavel-esir pavel-esir changed the title [IE][nGraph] resolve division to zero for FP16 [IE][nGraph] resolve division by zero for FP16 Dec 2, 2021
@pavel-esir pavel-esir requested a review from a team December 2, 2021 17:32

/**
* @ingroup ie_transformation_common_api
* @brief: clamps eps into fp16 minimal normalized value in input_1/Maximum(input_2, eps); input_1/Add(input_2, eps);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: looks like this is not al patterns that are supported. Better to keep patterns description in cpp.

@rkazants rkazants merged commit b6a5532 into openvinotoolkit:master Dec 7, 2021
@pavel-esir pavel-esir deleted the resolve_division_to_zero branch December 7, 2021 19:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants