auto max = quant_param->max();
auto scale = quant_param->scale();
auto zero_point = quant_param->zero_point();
+ auto quantized_dimension = quant_param->quantized_dimension();
os << " " + print_format2 + " ├── min : ";
::print_comma_sepearted(os, min);
os << " " + print_format2 + " ├── scale : ";
::print_comma_sepearted(os, scale);
os << std::endl;
- os << " " + print_format2 + "Â Â â\94\94── zero_point : ";
+ os << " " + print_format2 + "Â Â â\94\9c── zero_point : ";
::print_comma_sepearted(os, zero_point);
os << std::endl;
+ os << " " + print_format2 + " └── quantized_dimension : " << quantized_dimension;
+ os << std::endl;
}
// buffer
}
/**
- * This function writes data to given hdf5 file like below.
+ * This function writes vector data to given hdf5 file like below.
*
* GROUP "group_name"
* ㄴDATATYPE "type"
* ㄴDATA "data"
*/
template <typename T>
-void write_data_to_hdf5(H5::H5File &file, std::string &group_name, std::string dataset_name,
- const H5::PredType &type, const flatbuffers::Vector<T> *data,
- std::vector<hsize_t> dims)
+void write_vector_data_to_hdf5(H5::H5File &file, std::string &group_name, std::string dataset_name,
+ const H5::PredType &type, const flatbuffers::Vector<T> *data,
+ std::vector<hsize_t> dims)
{
if (data == nullptr)
return;
dataset->write(data->data(), type);
}
+/// @brief This function writes scalar data to given hdf5 file
+template <typename T>
+void write_scalar_data_to_hdf5(H5::H5File &file, std::string &group_name, std::string dataset_name,
+ const H5::PredType &type, T data)
+{
+ auto dataspace = std::make_unique<H5::DataSpace>(H5S_SCALAR);
+ auto dataset = std::make_unique<H5::DataSet>(
+ file.createDataSet(group_name + "/" + dataset_name, type, *dataspace));
+ dataset->write(&data, type);
+}
+
} // namespace
namespace circletensordump
auto buff_data_ptr = reader.buffers()->Get(buff_idx)->data();
if (buff_data_ptr)
{
- ::write_data_to_hdf5(file, group_name, "weights", ::hdf5_dtype_cast(tensor->type()),
- buff_data_ptr, ::hdf5_dims_cast(buff_data_ptr, tensor->shape()));
+ ::write_vector_data_to_hdf5(file, group_name, "weights", ::hdf5_dtype_cast(tensor->type()),
+ buff_data_ptr,
+ ::hdf5_dims_cast(buff_data_ptr, tensor->shape()));
}
// write quantization parameters
if (quant_param)
{
auto min = quant_param->min();
- ::write_data_to_hdf5(file, group_name, "min", H5::PredType::NATIVE_FLOAT, min,
- ::hdf5_dims_cast(min));
+ ::write_vector_data_to_hdf5(file, group_name, "min", H5::PredType::NATIVE_FLOAT, min,
+ ::hdf5_dims_cast(min));
auto max = quant_param->max();
- ::write_data_to_hdf5(file, group_name, "max", H5::PredType::NATIVE_FLOAT, max,
- ::hdf5_dims_cast(max));
+ ::write_vector_data_to_hdf5(file, group_name, "max", H5::PredType::NATIVE_FLOAT, max,
+ ::hdf5_dims_cast(max));
auto scale = quant_param->scale();
- ::write_data_to_hdf5(file, group_name, "scale", H5::PredType::NATIVE_FLOAT, scale,
- ::hdf5_dims_cast(scale));
+ ::write_vector_data_to_hdf5(file, group_name, "scale", H5::PredType::NATIVE_FLOAT, scale,
+ ::hdf5_dims_cast(scale));
auto zero_point = quant_param->zero_point();
- ::write_data_to_hdf5(file, group_name, "zero_point", H5::PredType::NATIVE_INT64, zero_point,
- ::hdf5_dims_cast(zero_point));
+ ::write_vector_data_to_hdf5(file, group_name, "zero_point", H5::PredType::NATIVE_INT64,
+ zero_point, ::hdf5_dims_cast(zero_point));
+ auto quantized_dimension = quant_param->quantized_dimension();
+ ::write_scalar_data_to_hdf5(file, group_name, "quantized_dimension",
+ H5::PredType::NATIVE_INT32, quantized_dimension);
}
}
}