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

Make leela2onnx Conv-nodes compatible with onnx2pytorch #1924

Merged
merged 9 commits into from
Nov 14, 2023
5 changes: 4 additions & 1 deletion src/neural/onnx/builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,15 @@ std::string PopulateStdNodeFields(pblczero::NodeProto* node,
std::string OnnxBuilder::Conv(const std::string& name,
const std::string& input_name,
const OnnxConst& kernel_weights,
const OnnxConst& bias_weights, int pads) {
const OnnxConst& bias_weights,
int filters,
Copy link
Member

Choose a reason for hiding this comment

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

Why not just do a 'kernel_weights.GetDimensions().back()` instead of passing the number of filters?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed, that's better

int pads) {
auto* node = model_.mutable_graph()->add_node();
auto out = PopulateStdNodeFields(node, name, input_name, "Conv");
node->add_input(AddInitializer(name + "/w/kernel", kernel_weights));
node->add_input(AddInitializer(name + "/w/bias", bias_weights));
AddIntsAttribute(node, "pads", {pads, pads, pads, pads});
AddIntsAttribute(node, "kernel_shape", {filters, filters});
return out;
}

Expand Down
2 changes: 1 addition & 1 deletion src/neural/onnx/builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class OnnxBuilder {
// node name.
std::string Conv(const std::string& name, const std::string& input_name,
const OnnxConst& kernel_weights,
const OnnxConst& bias_weights, int pads = 1);
const OnnxConst& bias_weights, int filters, int pads = 1);
std::string Add(const std::string& name, const std::string& input1,
const std::string& input2);
std::string Add(const std::string& name, const std::string& input1,
Expand Down
1 change: 1 addition & 0 deletions src/neural/onnx/converter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ std::string Converter::MakeConvBlock(
*GetWeghtsConverter(weights.weights,
{output_channels, input_channels, filters, filters}),
*GetWeghtsConverter(weights.biases, {output_channels}),
filters,
(filters - 1) / 2);

if (seunit) flow = MakeSqueezeAndExcite(builder, *seunit, flow, name + "/se");
Expand Down