Skip to content

Commit

Permalink
Merge branch 'Samsung:master' into rh-rh-only
Browse files Browse the repository at this point in the history
  • Loading branch information
BLee-bot authored Nov 6, 2024
2 parents 291d619 + da3e986 commit f352c41
Show file tree
Hide file tree
Showing 23 changed files with 351 additions and 35 deletions.
4 changes: 4 additions & 0 deletions compiler/circlechef/circle/src/Convert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ circlechef::TensorType as_circlechef_type(const circle::TensorType type)
return circlechef::INT16;
case circle::TensorType_INT4:
return circlechef::INT4;
case circle::TensorType_MXFP4:
return circlechef::MXFP4;
case circle::TensorType_MXINT8:
return circlechef::MXINT8;
// TODO handle other types
// TensorType_FLOAT16
// TensorType_STRING
Expand Down
4 changes: 4 additions & 0 deletions compiler/circlechef/core/src/Convert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ circle::TensorType as_circle_tensortype(const circlechef::TensorType &value)
return circle::TensorType_STRING;
case circlechef::BOOL:
return circle::TensorType_BOOL;
case circlechef::MXFP4:
return circle::TensorType_MXFP4;
case circlechef::MXINT8:
return circle::TensorType_MXINT8;
default:
break;
}
Expand Down
2 changes: 2 additions & 0 deletions compiler/circlechef/core/src/Convert.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ TEST(ConvertTest, as_circle_tensortype)
ASSERT_EQ(circle::TensorType_UINT8, as_circle_tensortype(circlechef::UINT8));
ASSERT_EQ(circle::TensorType_UINT4, as_circle_tensortype(circlechef::UINT4));
ASSERT_EQ(circle::TensorType_BOOL, as_circle_tensortype(circlechef::BOOL));
ASSERT_EQ(circle::TensorType_MXFP4, as_circle_tensortype(circlechef::MXFP4));
ASSERT_EQ(circle::TensorType_MXINT8, as_circle_tensortype(circlechef::MXINT8));
}

TEST(ConvertTest, as_circle_tensortype_NEG)
Expand Down
29 changes: 29 additions & 0 deletions compiler/circlechef/core/src/Op/Dequantize.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright (c) 2024 Samsung Electronics Co., Ltd. All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "Dequantize.h"

#include "Convert.h"

flatbuffers::Offset<void> DequantizeChef::value(flatbuffers::FlatBufferBuilder &fbb) const
{
return flatbuffers::Offset<void>();
}

std::unique_ptr<OpChef> DequantizeChefFactory::create(const circlechef::Operation *operation) const
{
return std::unique_ptr<OpChef>{new DequantizeChef{operation}};
}
49 changes: 49 additions & 0 deletions compiler/circlechef/core/src/Op/Dequantize.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright (c) 2024 Samsung Electronics Co., Ltd. All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef __OP_DEQUANTIZE_H__
#define __OP_DEQUANTIZE_H__

#include "OpChef.h"

class DequantizeChef final : public OpChef
{
public:
explicit DequantizeChef(const circlechef::Operation *operation) : _operation{operation}
{
// DO NOTHING
}

public:
circle::BuiltinOperator code(void) const override { return circle::BuiltinOperator_DEQUANTIZE; }

circle::BuiltinOptions type(void) const override
{
return circle::BuiltinOptions_DequantizeOptions;
}

flatbuffers::Offset<void> value(flatbuffers::FlatBufferBuilder &fbb) const override;

private:
const circlechef::Operation *_operation;
};

struct DequantizeChefFactory final : public OpChefFactory
{
std::unique_ptr<OpChef> create(const circlechef::Operation *operation) const override;
};

#endif // __OP_DEQUANTIZE_H__
29 changes: 29 additions & 0 deletions compiler/circlechef/core/src/Op/Quantize.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright (c) 2024 Samsung Electronics Co., Ltd. All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "Quantize.h"

#include "Convert.h"

flatbuffers::Offset<void> QuantizeChef::value(flatbuffers::FlatBufferBuilder &fbb) const
{
return flatbuffers::Offset<void>();
}

std::unique_ptr<OpChef> QuantizeChefFactory::create(const circlechef::Operation *operation) const
{
return std::unique_ptr<OpChef>{new QuantizeChef{operation}};
}
49 changes: 49 additions & 0 deletions compiler/circlechef/core/src/Op/Quantize.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright (c) 2024 Samsung Electronics Co., Ltd. All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef __OP_QUANTIZE_H__
#define __OP_QUANTIZE_H__

#include "OpChef.h"

class QuantizeChef final : public OpChef
{
public:
explicit QuantizeChef(const circlechef::Operation *operation) : _operation{operation}
{
// DO NOTHING
}

public:
circle::BuiltinOperator code(void) const override { return circle::BuiltinOperator_QUANTIZE; }

circle::BuiltinOptions type(void) const override
{
return circle::BuiltinOptions_QuantizeOptions;
}

flatbuffers::Offset<void> value(flatbuffers::FlatBufferBuilder &fbb) const override;

private:
const circlechef::Operation *_operation;
};

struct QuantizeChefFactory final : public OpChefFactory
{
std::unique_ptr<OpChef> create(const circlechef::Operation *operation) const override;
};

#endif // __OP_QUANTIZE_H__
2 changes: 2 additions & 0 deletions compiler/circlechef/core/src/OpChef.def
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
OP_CHEF(BatchMatMul, BatchMatMulChefFactory)
OP_CHEF(BCQFullyConnected, BCQFullyConnectedChefFactory)
OP_CHEF(BCQGather, BCQGatherChefFactory)
OP_CHEF(Dequantize, DequantizeChefFactory)
OP_CHEF(FullyConnected, FullyConnectedChefFactory)
OP_CHEF(GRU, GRUChefFactory)
OP_CHEF(InstanceNorm, InstanceNormChefFactory)
OP_CHEF(RmsNorm, RmsNormChefFactory)
OP_CHEF(RoPE, RoPEChefFactory)
OP_CHEF(Quantize, QuantizeChefFactory)
2 changes: 2 additions & 0 deletions compiler/circlechef/core/src/OpChefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@
#include "Op/BatchMatMul.h"
#include "Op/BCQFullyConnected.h"
#include "Op/BCQGather.h"
#include "Op/Dequantize.h"
#include "Op/FullyConnected.h"
#include "Op/GRU.h"
#include "Op/InstanceNorm.h"
#include "Op/RmsNorm.h"
#include "Op/RoPE.h"
#include "Op/Quantize.h"

#endif // __OP_CHEFS_H__
4 changes: 3 additions & 1 deletion compiler/circlechef/proto/circlechef.proto
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ package circlechef;
// - Added name, version(default as 1), graph in ModelRecipe
//

// This enum value corresponds to TensorType in TensorFlow Lite schema
// This enum value corresponds to TensorType in Circle schema
enum TensorType {
MXINT8 = -7;
MXFP4 = -6;
UINT4 = -1;
FLOAT32 = 0;
INT32 = 2;
Expand Down
2 changes: 2 additions & 0 deletions compiler/common-artifacts/exclude.lst
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@ tcgenerate(BCQFullyConnected_001)
tcgenerate(BCQGather_000)
tcgenerate(CircleBatchMatMul_I4_000)
tcgenerate(CircleBatchMatMul_U4_000)
tcgenerate(CircleBatchMatMul_MXFP4_000)
tcgenerate(CircleBatchMatMul_MXINT8_000)
tcgenerate(CircleFullyConnected_U4_000)
tcgenerate(CircleFullyConnected_U4_001)
tcgenerate(CircleFullyConnected_U4_002)
Expand Down
4 changes: 4 additions & 0 deletions compiler/loco/include/loco/IR/DataType.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ enum class DataType

// WARNING STRING is NOT fully supported yet
STRING, // String

// Microscaling data type
MXFP4,
MXINT8,
};

} // namespace loco
Expand Down
5 changes: 5 additions & 0 deletions compiler/luci/export/src/CircleExporterUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ circle::TensorType to_circle_tensortype(loco::DataType type)
case loco::DataType::STRING:
return circle::TensorType_STRING;

case loco::DataType::MXFP4:
return circle::TensorType_MXFP4;
case loco::DataType::MXINT8:
return circle::TensorType_MXINT8;

default:
INTERNAL_EXN_V("failed to convert unsupported loco::DataType", oops::to_uint32(type));
}
Expand Down
4 changes: 4 additions & 0 deletions compiler/luci/import/src/CircleReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ loco::DataType luci_datatype(const circle::TensorType type)
return loco::DataType::S8;
case circle::TensorType_INT4:
return loco::DataType::S4;
case circle::TensorType_MXFP4:
return loco::DataType::MXFP4;
case circle::TensorType_MXINT8:
return loco::DataType::MXINT8;
default:
break;
}
Expand Down
5 changes: 5 additions & 0 deletions compiler/luci/logex/src/CircleNodeSummaryBuilders.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ std::string to_str(loco::DataType type)
case loco::DataType::BOOL:
return "BOOL";

case loco::DataType::MXFP4:
return "MXFP4";
case loco::DataType::MXINT8:
return "MXINT8";

default:
return "Error";
}
Expand Down
5 changes: 5 additions & 0 deletions compiler/onnx-tools/onnx-dump.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,13 @@ def _dump_operators(onnx_model):
opcodes_dict[node.op_type] = 1

print("[Operators] ---------------------------")
total_nodes = 0
for opcode_key in opcodes_dict:
print("{:>5} {}".format(opcodes_dict[opcode_key], opcode_key))
total_nodes = total_nodes + opcodes_dict[opcode_key]

print("----- -----")
print("{:>5} {}".format(total_nodes, 'Total'))

print("")

Expand Down
1 change: 1 addition & 0 deletions compiler/record-hessian/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ target_link_libraries(record-hessian luci_export)
target_link_libraries(record-hessian luci_interpreter)
target_link_libraries(record-hessian luci_log)
target_link_libraries(record-hessian dio_hdf5)
target_link_libraries(record-hessian nncc_common)

install(TARGETS record-hessian DESTINATION lib)
install(DIRECTORY include/ DESTINATION include
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ class HessianComputer

void unfold(std::vector<float> &buf, uint32_t input_n, uint32_t input_h, uint32_t input_w,
uint32_t input_c, uint32_t stride_h, uint32_t stride_w, uint32_t dilation_h,
uint32_t dilation_w, uint32_t kernel_oc, uint32_t kernel_h, uint32_t kernel_w,
uint32_t kernel_ic);
uint32_t dilation_w, uint32_t kernel_h, uint32_t kernel_w, uint32_t kernel_ic);

} // namespace record_hessian

Expand Down
Loading

0 comments on commit f352c41

Please sign in to comment.