Skip to content

Commit

Permalink
pnnx: Fix save_ncnn with fp16=1
Browse files Browse the repository at this point in the history
Signed-off-by: Molly Sophia <mollysophia379@gmail.com>
  • Loading branch information
MollySophia committed Sep 1, 2023
1 parent 14b000d commit eb3061c
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions tools/pnnx/src/save_ncnn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,15 @@ int save_ncnn(const Graph& g, const std::string& parampath, const std::string& b

const Attribute& attr = it.second;

if (fp16 && (((attr.type == 0 && attr.data == std::vector<char> {0, 0, 0, 0}) || attr.type == 1)))
{
// write fp16 flag
unsigned int fp16_flag = 0x01306B47;
fwrite((const char*)&fp16_flag, sizeof(fp16_flag), 1, binfp);

is_type_flag_fp32 = true;
}

if (fp16 && is_type_flag_fp32)
{
// fp32 -> fp16
Expand All @@ -287,16 +296,6 @@ int save_ncnn(const Graph& g, const std::string& parampath, const std::string& b
continue;
}

if (fp16 && attr.type == 0 && attr.data == std::vector<char> {0, 0, 0, 0})
{
// write fp16 flag
unsigned int fp16_flag = 0x01306B47;
fwrite((const char*)&fp16_flag, sizeof(fp16_flag), 1, binfp);

is_type_flag_fp32 = true;
continue;
}

fwrite(attr.data.data(), attr.data.size(), 1, binfp);
}

Expand Down

0 comments on commit eb3061c

Please sign in to comment.