Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
gaoqiong
MIGraphX
Commits
961f0e1b
Commit
961f0e1b
authored
Sep 26, 2023
by
charlie
Browse files
Debugging edits
Softmax fp32 propagate_constant fp64 layernorm fp32
parent
ecfd3834
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
71 additions
and
6 deletions
+71
-6
src/driver/verify.cpp
src/driver/verify.cpp
+3
-0
src/onnx/onnx_parser.cpp
src/onnx/onnx_parser.cpp
+0
-1
src/onnx/parse_softmax.cpp
src/onnx/parse_softmax.cpp
+7
-0
src/propagate_constant.cpp
src/propagate_constant.cpp
+38
-3
src/quantize_fp16.cpp
src/quantize_fp16.cpp
+10
-2
src/targets/gpu/prefuse_ops.cpp
src/targets/gpu/prefuse_ops.cpp
+13
-0
No files found.
src/driver/verify.cpp
View file @
961f0e1b
...
@@ -37,6 +37,9 @@ inline namespace MIGRAPHX_INLINE_NS {
...
@@ -37,6 +37,9 @@ inline namespace MIGRAPHX_INLINE_NS {
std
::
vector
<
argument
>
run_ref
(
program
p
,
const
parameter_map
&
inputs
)
std
::
vector
<
argument
>
run_ref
(
program
p
,
const
parameter_map
&
inputs
)
{
{
// DEBUG
quantize_fp16
(
p
);
p
.
compile
(
migraphx
::
make_target
(
"ref"
));
p
.
compile
(
migraphx
::
make_target
(
"ref"
));
auto
out
=
p
.
eval
(
inputs
);
auto
out
=
p
.
eval
(
inputs
);
std
::
cout
<<
p
<<
std
::
endl
;
std
::
cout
<<
p
<<
std
::
endl
;
...
...
src/onnx/onnx_parser.cpp
View file @
961f0e1b
...
@@ -555,7 +555,6 @@ literal onnx_parser::parse_tensor(const onnx::TensorProto& t) const
...
@@ -555,7 +555,6 @@ literal onnx_parser::parse_tensor(const onnx::TensorProto& t) const
shape
onnx_parser
::
parse_type
(
const
onnx
::
TypeProto
&
t
)
const
shape
onnx_parser
::
parse_type
(
const
onnx
::
TypeProto
&
t
)
const
{
{
shape
::
type_t
shape_type
=
get_type
(
t
.
tensor_type
().
elem_type
());
shape
::
type_t
shape_type
=
get_type
(
t
.
tensor_type
().
elem_type
());
std
::
vector
<
shape
::
dynamic_dimension
>
dynamic_dims
;
std
::
vector
<
shape
::
dynamic_dimension
>
dynamic_dims
;
auto
&&
tensor_dims
=
t
.
tensor_type
().
shape
().
dim
();
auto
&&
tensor_dims
=
t
.
tensor_type
().
shape
().
dim
();
std
::
transform
(
tensor_dims
.
begin
(),
std
::
transform
(
tensor_dims
.
begin
(),
...
...
src/onnx/parse_softmax.cpp
View file @
961f0e1b
...
@@ -57,7 +57,14 @@ struct parse_softmax : op_parser<parse_softmax>
...
@@ -57,7 +57,14 @@ struct parse_softmax : op_parser<parse_softmax>
axis
=
parser
.
parse_value
(
info
.
attributes
.
at
(
"axis"
)).
at
<
int
>
();
axis
=
parser
.
parse_value
(
info
.
attributes
.
at
(
"axis"
)).
at
<
int
>
();
}
}
// previous version
return
info
.
add_instruction
(
make_op
(
opd
.
op_name
,
{{
"axis"
,
axis
}}),
args
);
return
info
.
add_instruction
(
make_op
(
opd
.
op_name
,
{{
"axis"
,
axis
}}),
args
);
// converted version
// auto convert0 = info.add_instruction(make_op("convert", {{"target_type",
// shape::float_type}}), args); auto softmax_ins = info.add_instruction(make_op(opd.op_name,
// {{"axis", axis}}), convert0); return info.add_instruction(make_op("convert",
// {{"target_type", shape::half_type}}), softmax_ins);
}
}
};
};
...
...
src/propagate_constant.cpp
View file @
961f0e1b
...
@@ -29,6 +29,7 @@
...
@@ -29,6 +29,7 @@
#include <migraphx/par_for.hpp>
#include <migraphx/par_for.hpp>
#include <migraphx/env.hpp>
#include <migraphx/env.hpp>
#include <unordered_set>
#include <unordered_set>
#include <migraphx/make_op.hpp>
namespace
migraphx
{
namespace
migraphx
{
inline
namespace
MIGRAPHX_INLINE_NS
{
inline
namespace
MIGRAPHX_INLINE_NS
{
...
@@ -79,9 +80,43 @@ void propagate_constant::apply(module& m) const
...
@@ -79,9 +80,43 @@ void propagate_constant::apply(module& m) const
// Compute literals in parallel
// Compute literals in parallel
std
::
vector
<
instruction_ref
>
const_instrs_vec
{
const_instrs
.
begin
(),
const_instrs
.
end
()};
std
::
vector
<
instruction_ref
>
const_instrs_vec
{
const_instrs
.
begin
(),
const_instrs
.
end
()};
std
::
vector
<
argument
>
literals
(
const_instrs_vec
.
size
());
std
::
vector
<
argument
>
literals
(
const_instrs_vec
.
size
());
par_for
(
const_instrs_vec
.
size
(),
1
,
[
&
](
const
auto
i
)
{
for
(
int
i
=
0
;
i
<
const_instrs_vec
.
size
();
++
i
)
literals
[
i
]
=
const_instrs_vec
[
i
]
->
eval
();
{
// DEBUG
auto
ins
=
const_instrs_vec
[
i
];
if
(
ins
->
get_shape
().
type
()
==
shape
::
half_type
)
{
auto
inputs
=
ins
->
inputs
();
std
::
vector
<
instruction_ref
>
new_inputs
(
inputs
.
size
());
std
::
vector
<
instruction_ref
>
added_instructions
;
std
::
transform
(
inputs
.
begin
(),
inputs
.
end
(),
new_inputs
.
begin
(),
[
&
](
auto
input
)
{
auto
input_type
=
input
->
get_shape
().
type
();
if
(
input_type
!=
shape
::
half_type
and
input_type
!=
shape
::
float_type
)
return
input
;
auto
ai
=
m
.
add_instruction
(
make_op
(
"convert"
,
{{
"target_type"
,
shape
::
double_type
}}),
input
);
added_instructions
.
push_back
(
ai
);
return
ai
;
});
});
auto
new_ins
=
m
.
add_instruction
(
ins
->
get_operator
(),
new_inputs
);
added_instructions
.
push_back
(
new_ins
);
auto
after_convert
=
m
.
add_instruction
(
make_op
(
"convert"
,
{{
"target_type"
,
ins
->
get_shape
().
type
()}}),
new_ins
);
added_instructions
.
push_back
(
after_convert
);
literals
[
i
]
=
after_convert
->
eval
();
for
(
auto
a_ins
:
added_instructions
)
{
m
.
remove_instruction
(
a_ins
);
}
}
else
{
literals
[
i
]
=
const_instrs_vec
[
i
]
->
eval
();
}
// Original
// literals[i] = const_instrs_vec[i]->eval();
}
// Replace instructions in m
// Replace instructions in m
for
(
size_t
i
=
0
;
i
<
const_instrs_vec
.
size
();
i
++
)
for
(
size_t
i
=
0
;
i
<
const_instrs_vec
.
size
();
i
++
)
...
...
src/quantize_fp16.cpp
View file @
961f0e1b
...
@@ -56,10 +56,18 @@ static void quantize_module(module& m, const std::vector<std::string>& ins_names
...
@@ -56,10 +56,18 @@ static void quantize_module(module& m, const std::vector<std::string>& ins_names
auto
inputs
=
ins
->
inputs
();
auto
inputs
=
ins
->
inputs
();
std
::
transform
(
inputs
.
begin
(),
inputs
.
end
(),
inputs
.
begin
(),
[
&
](
auto
input
)
{
std
::
transform
(
inputs
.
begin
(),
inputs
.
end
(),
inputs
.
begin
(),
[
&
](
auto
input
)
{
auto
input_type
=
input
->
get_shape
().
type
();
auto
input_type
=
input
->
get_shape
().
type
();
if
(
input_type
!=
shape
::
float_type
and
input_type
!=
shape
::
double_type
)
// ORIGINAL
// if(input_type != shape::float_type and input_type != shape::double_type)
// return input;
// return m.insert_instruction(
// ins, make_op("convert", {{"target_type", shape::half_type}}), input);
// DEBUG hack to fp32 atleast
if
(
input_type
!=
shape
::
half_type
)
return
input
;
return
input
;
return
m
.
insert_instruction
(
return
m
.
insert_instruction
(
ins
,
make_op
(
"convert"
,
{{
"target_type"
,
shape
::
half_type
}}),
input
);
ins
,
make_op
(
"convert"
,
{{
"target_type"
,
shape
::
float_type
}}),
input
);
});
});
// Insert quantized ins
// Insert quantized ins
...
...
src/targets/gpu/prefuse_ops.cpp
View file @
961f0e1b
...
@@ -99,6 +99,19 @@ struct find_layernorm
...
@@ -99,6 +99,19 @@ struct find_layernorm
if
(
contains
(
r
.
instructions
,
"eps"
))
if
(
contains
(
r
.
instructions
,
"eps"
))
eps
=
r
.
instructions
[
"eps"
]
->
eval
().
at
<
float
>
();
eps
=
r
.
instructions
[
"eps"
]
->
eval
().
at
<
float
>
();
// DEBUG
// if(ins->get_shape().type() == shape::half_type)
//{
// auto bconvert = m.insert_instruction(ins, make_op("convert", {{"target_type",
// shape::float_type}}), x_ins); auto ln_ins = m.insert_instruction(ins, layernorm{eps},
// bconvert); m.replace_instruction(ins, make_op("convert", {{"target_type",
// shape::half_type}}), ln_ins);
//}
// else
//{
// m.replace_instruction(ins, layernorm{eps}, x_ins);
//}
m
.
replace_instruction
(
ins
,
layernorm
{
eps
},
x_ins
);
m
.
replace_instruction
(
ins
,
layernorm
{
eps
},
x_ins
);
}
}
};
};
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment