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

Change driver verify to check for fp16 and --fp16 #2334

Merged
merged 5 commits into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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: 7 additions & 0 deletions src/driver/argument_parser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,13 @@ struct value_parser
}
};

// version for std::optional object
template <class T>
struct value_parser<std::optional<T>>
{
static T apply(const std::string& x) { return value_parser<T>::apply(x); }
Copy link
Collaborator

Choose a reason for hiding this comment

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

Actually this should return std::optional<T>: static std::optional<T> apply(const std::string& x) { return value_parser<T>::apply(x); }.

};

struct argument_parser
{
struct argument
Expand Down
47 changes: 4 additions & 43 deletions src/driver/main.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
ii The MIT License (MIT)
* The MIT License (MIT)
*
* Copyright (c) 2015-2022 Advanced Micro Devices, Inc. All rights reserved.
*
Expand Down Expand Up @@ -41,8 +41,6 @@ ii The MIT License (MIT)
#include <migraphx/json.hpp>
#include <migraphx/version.h>

#include <migraphx/instruction.hpp>
#include <migraphx/module_ref.hpp>
#include <migraphx/dead_code_elimination.hpp>
#include <migraphx/eliminate_identity.hpp>
#include <migraphx/eliminate_pad.hpp>
Expand Down Expand Up @@ -539,39 +537,6 @@ struct params : command<params>
}
};

/**
* Gives tolerances based on user input (`rms_tol`, `atol`, `rtol` parameters) and defaults.
* Sets to fp16 tolerances if `quantize` input is fp16 or any fp16 instruction in found in the model.
*/
verify::tolerance get_tolerances(const program& p, precision quantize, std::optional<double> rms_tol, std::optional<double> atol, std::optional<double> rtol)
{
bool has_fp16 = any_of(p.get_modules(), [](auto&& m) {
return any_of(*m, [](auto&& ins) {
return (ins.get_shape().type() == shape::half_type);
});
});
migraphx::verify::tolerance result{};
if(has_fp16 or quantize == precision::fp16)
{
result.rms_tol = 8e-2;
result.atol = 4e-2;
result.rtol = 4e-2;
}
if(rms_tol)
{
result.rms_tol = *rms_tol;
}
if(atol)
{
result.atol = *atol;
}
if(rtol)
{
result.rtol = *rtol;
}
return result;
}

struct verify : command<verify>
{
compiler c;
Expand All @@ -583,13 +548,9 @@ struct verify : command<verify>
void parse(argument_parser& ap)
{
c.parse(ap);
ap(*rms_tol, {"--rms-tol"}, ap.help("Tolerance for the RMS error"));
ap(*atol,
{"--atol"},
ap.help("Tolerance for the elementwise absolute difference"));
ap(*rtol,
{"--rtol"},
ap.help("Tolerance for the elementwise relative difference"));
ap(rms_tol, {"--rms-tol"}, ap.help("Tolerance for the RMS error"));
ap(atol, {"--atol"}, ap.help("Tolerance for the elementwise absolute difference"));
ap(rtol, {"--rtol"}, ap.help("Tolerance for the elementwise relative difference"));
ap(per_instruction,
{"-i", "--per-instruction"},
ap.help("Verify each instruction"),
Expand Down
36 changes: 36 additions & 0 deletions src/driver/verify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,42 @@ namespace migraphx {
namespace driver {
inline namespace MIGRAPHX_INLINE_NS {

/**
* Gives tolerances based on user input (`rms_tol`, `atol`, `rtol` parameters) and defaults.
* Sets to fp16 tolerances if `quantize` input is fp16 or any fp16 instruction in found in the
* model.
*/
verify::tolerance get_tolerances(const program& p,
precision quantize,
std::optional<double> rms_tol,
std::optional<double> atol,
std::optional<double> rtol)
{
bool has_fp16 = any_of(p.get_modules(), [](auto&& m) {
return any_of(*m, [](auto&& ins) { return (ins.get_shape().type() == shape::half_type); });
});
migraphx::verify::tolerance result{};
if(has_fp16 or quantize == precision::fp16)
{
result.rms_tol = 8e-2;
result.atol = 4e-2;
result.rtol = 4e-2;
}
if(rms_tol)
{
result.rms_tol = *rms_tol;
}
if(atol)
{
result.atol = *atol;
}
if(rtol)
{
result.rtol = *rtol;
}
return result;
}

std::vector<argument> run_ref(program p, const parameter_map& inputs)
{
p.compile(migraphx::make_target("ref"));
Expand Down
6 changes: 6 additions & 0 deletions src/driver/verify.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ namespace migraphx {
namespace driver {
inline namespace MIGRAPHX_INLINE_NS {

verify::tolerance get_tolerances(const program& p,
precision quantize,
std::optional<double> rms_tol,
std::optional<double> atol,
std::optional<double> rtol);

void verify_program(const std::string& name,
const program& p,
const target& t,
Expand Down