Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
160 changes: 160 additions & 0 deletions lib/models/include/models/yolov10/yolov10.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
/**
* @file yolov10.h
*
* @brief YOLOv10 detection model
*/

#ifndef _FLEXFLOW_LIB_MODELS_INCLUDE_MODELS_YOLOV10_H
#define _FLEXFLOW_LIB_MODELS_INCLUDE_MODELS_YOLOV10_H

#include "models/yolov10/yolov10_config.dtg.h"
#include "pcg/computation_graph_builder.h"

namespace FlexFlow {

// Helper types

/**
* @brief Hold per-layer tensor / num_channels information.
*/
struct YOLOv10LayerChannelTensor {
positive_int channels_;
tensor_guid_t tensor_;
};

/**
* @brief Hold detection outputs.
*/
struct YOLOv10DetectHeadOutputs {
tensor_guid_t boxes; // (B, 4*reg_max, sum_i(Hi*Wi))
tensor_guid_t scores; // (B, nc, sum_i(Hi*Wi))
std::vector<tensor_guid_t> feats; // passthrough features
};

// Helper functions to construct the YOLOv10 model

/**
* @brief Get the default YOLOv10 config.
*
* @details The configs here refer to the example at
* https://github.com/ultralytics/ultralytics/blob/main/ultralytics/cfg/models/v10/yolov10x.yaml.
*/
YOLOv10Config get_default_yolov10_config();

bool is_yolov10_repeat_module(YOLOv10Module module_type);

YOLOv10LayerChannelTensor create_yolov10_concat_layer(
ComputationGraphBuilder &cgb,
std::vector<YOLOv10LayerChannelTensor> const &layers_cache,
std::vector<int> const &input_tensor_index,
nonnegative_int concat_dim);

YOLOv10LayerChannelTensor create_yolov10_upsample_layer(
ComputationGraphBuilder &cgb,
std::vector<YOLOv10LayerChannelTensor> const &layers_cache);

YOLOv10LayerChannelTensor
create_yolov10_conv_module(ComputationGraphBuilder &cgb,
tensor_guid_t const &input_tensor,
positive_int const &channel_in,
std::vector<int> const &conv_module_args);

YOLOv10LayerChannelTensor
create_yolov10_scdown_module(ComputationGraphBuilder &cgb,
tensor_guid_t const &input_tensor,
positive_int const &channel_in,
std::vector<int> const &scdown_module_args);

YOLOv10LayerChannelTensor
create_yolov10_sppf_module(ComputationGraphBuilder &cgb,
tensor_guid_t const &input_tensor,
positive_int const &channel_in,
std::vector<int> const &sppf_module_args);

YOLOv10LayerChannelTensor
create_yolov10_psa_module(ComputationGraphBuilder &cgb,
tensor_guid_t const &input_tensor,
positive_int const &channel_in,
std::vector<int> const &psa_module_args);

YOLOv10LayerChannelTensor create_yolov10_bottleneck_module(
ComputationGraphBuilder &cgb,
tensor_guid_t const &input_tensor,
positive_int const &channel_in,
std::vector<int> const &bottleneck_module_args);

YOLOv10LayerChannelTensor
create_yolov10_c2f_module(ComputationGraphBuilder &cgb,
tensor_guid_t const &input_tensor,
positive_int const &channel_in,
std::vector<int> const &c2f_module_args);

YOLOv10LayerChannelTensor
create_yolov10_cib_module(ComputationGraphBuilder &cgb,
tensor_guid_t const &input_tensor,
positive_int const &channel_in,
std::vector<int> const &cib_module_args);

YOLOv10LayerChannelTensor
create_yolov10_c2fcib_module(ComputationGraphBuilder &cgb,
tensor_guid_t const &input_tensor,
positive_int const &channel_in,
std::vector<int> const &c2fcib_module_args);

YOLOv10LayerChannelTensor
create_yolov10_detect_box_head_one_level(ComputationGraphBuilder &cgb,
tensor_guid_t const &feat,
positive_int const &feat_channels,
int c2,
int reg_max);

YOLOv10LayerChannelTensor create_yolov10_v10detect_cls_head_one_level(
ComputationGraphBuilder &cgb,
tensor_guid_t const &feat,
positive_int const &feat_channels,
int c3,
int nc);

YOLOv10DetectHeadOutputs create_yolov10_v10detect_forward(
ComputationGraphBuilder &cgb,
std::vector<tensor_guid_t> const &feats,
std::vector<positive_int> const &feat_channels,
int nc,
int reg_max);

YOLOv10LayerChannelTensor create_yolov10_base_module_layer(
ComputationGraphBuilder &cgb,
std::vector<YOLOv10LayerChannelTensor> const &layers_cache,
YOLOv10Module module_type,
std::vector<int> const &input_tensor_index,
positive_int const &num_module_repeats,
std::vector<int> const &module_args);

YOLOv10LayerChannelTensor create_yolov10_detect_layer(
ComputationGraphBuilder &cgb,
std::vector<YOLOv10LayerChannelTensor> const &layers_cache,
YOLOv10Config const &model_config,
std::vector<int> const &input_tensor_index,
std::vector<int> const &module_args);

tensor_guid_t create_yolov10_tensor(ComputationGraphBuilder &cgb,
FFOrdered<positive_int> const &dims,
DataType const &data_type);

YOLOv10LayerChannelTensor create_yolov10_layer(
ComputationGraphBuilder &cgb,
YOLOv10Config const &model_config,
YOLOv10LayerConfig const &layer_config,
std::vector<YOLOv10LayerChannelTensor> const &layers_cache);

/**
* @brief Get the YOLOv10 computation graph.
*
* @param YOLOv10Config The config of YOLOv10 model.
* @return ComputationGraph The computation graph of a YOLOv10 model.
*/
ComputationGraph get_yolov10_computation_graph(YOLOv10Config const &config);

} // namespace FlexFlow

#endif
49 changes: 49 additions & 0 deletions lib/models/include/models/yolov10/yolov10_config.dtg.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
namespace = "FlexFlow"
name = "YOLOv10Config"
type = "struct"

features = [
"eq",
"ord",
"hash",
"json",
"rapidcheck",
"fmt",
]

includes = [
"<vector>",
"<string>",
"models/yolov10/yolov10_module.dtg.h",
"models/yolov10/yolov10_layer_config.dtg.h",
"utils/positive_int/positive_int.h",
]

src_includes = [
"utils/fmt/vector.h",
"utils/hash/vector.h",
]


[[fields]]
name = "num_input_channels"
type = "::FlexFlow::positive_int"


[[fields]]
name = "num_classes"
type = "::FlexFlow::positive_int"


[[fields]]
name = "model_scales"
type = "std::vector<float>"


[[fields]]
name = "model_layers"
type = "std::vector<::FlexFlow::YOLOv10LayerConfig>"

[[fields]]
name = "batch_size"
type = "::FlexFlow::positive_int"
44 changes: 44 additions & 0 deletions lib/models/include/models/yolov10/yolov10_layer_config.dtg.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
namespace = "FlexFlow"
name = "YOLOv10LayerConfig"
type = "struct"

features = [
"eq",
"ord",
"hash",
"json",
"rapidcheck",
"fmt",
]

includes = [
"<vector>",
"<string>",
"models/yolov10/yolov10_module.dtg.h",
"utils/positive_int/positive_int.h",
]

src_includes = [
"utils/fmt/vector.h",
"utils/hash/vector.h",
]


[[fields]]
name = "input_tensor_index"
type = "std::vector<int>"


[[fields]]
name = "num_module_repeats"
type = "::FlexFlow::positive_int"


[[fields]]
name = "module_type"
type = "::FlexFlow::YOLOv10Module"


[[fields]]
name = "module_args"
type = "std::vector<int>"
32 changes: 32 additions & 0 deletions lib/models/include/models/yolov10/yolov10_module.dtg.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
namespace = "FlexFlow"
name = "YOLOv10Module"
type = "enum"

features = ["hash", "json", "rapidcheck", "fmt"]

[[values]]
name = "Conv"

[[values]]
name = "C2f"

[[values]]
name = "SCDown"

[[values]]
name = "C2fCIB"

[[values]]
name = "SPPF"

[[values]]
name = "PSA"

[[values]]
name = "Upsample"

[[values]]
name = "Concat"

[[values]]
name = "v10Detect"
Loading
Loading