Skip to content

Commit

Permalink
[Subgraph] bugfix in subgraph initialization.
Browse files Browse the repository at this point in the history
- The previous version didn't implement a constructor for subgraph
  initialization.
- This commit resolves the issue.

Signed-off-by: Eunju Yang <[email protected]>
  • Loading branch information
EunjuYang committed Mar 4, 2025
1 parent 84968fc commit deeae64
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 15 deletions.
3 changes: 2 additions & 1 deletion nntrainer/graph/network_graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@ void NetworkGraph::addLayer(std::shared_ptr<LayerNode> layer) {
if (!graph.verifyNode(graph_name)) {
/// @todo choose SubGraph type based on the layer compute_engine
// Based on the property, SubGraphNode type should be changed
auto sg = std::make_shared<SubGraphCpu>(tensor_manager);
auto sg = std::make_shared<SubGraphCpu>(
tensor_manager, exec_mode, lookahead, tensor_format, tensor_dtype_str);
sg->setName(graph_name);
graph.addNode(SGNODE(sg));
}
Expand Down
13 changes: 10 additions & 3 deletions nntrainer/graph/network_graph.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,11 @@ class NetworkGraph {
optimize_memory(true),
exec_mode(ExecutionMode::TRAIN),
tensor_format("NCHW"),
tensor_dtype_str("FP32-FP32"),
tensor_dtype(split("FP32-FP32", getRegex("\\-"))),
is_clip_grad(false),
loss_scale(1.0f) {
loss_scale(1.0f),
lookahead(0) {
nan_count = 0;

/**
Expand Down Expand Up @@ -97,16 +99,19 @@ class NetworkGraph {
optimize_memory(true),
exec_mode(mode),
tensor_format(tensor_format_),
tensor_dtype_str(tensor_dtype_),
tensor_dtype(split(tensor_dtype_, getRegex("\\-"))),
is_clip_grad(false),
loss_scale(1.0f) {
loss_scale(1.0f),
lookahead(lookahead) {
nan_count = 0;

/**
* @note This code written based on the assumption that he graph consists
* with only one default subgraph node. It needs to be updated.
*/
auto sg = std::make_shared<SubGraphCpu>(tensor_manager);
auto sg = std::make_shared<SubGraphCpu>(tensor_manager, mode, lookahead,
tensor_format_, tensor_dtype_);
sg->setName("default");
graph.addNode(SGNODE(sg));
}
Expand Down Expand Up @@ -593,6 +598,7 @@ class NetworkGraph {
currently set or previously set */

std::string tensor_format; /**< Model Tensor Format: NCHW or NHWC */
std::string tensor_dtype_str;

std::vector<std::string> tensor_dtype; /**< Model Tensor Type: FP32, FP16 */

Expand All @@ -604,6 +610,7 @@ class NetworkGraph {
bool is_clip_grad;
float loss_scale;
unsigned int nan_count;
unsigned int lookahead;
};

} // namespace nntrainer
Expand Down
25 changes: 18 additions & 7 deletions nntrainer/graph/subgraph_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,20 @@ class SubGraphBase : public GraphNode {

public:
/**
* @brief Constructor of NeuralNetwork SubGraph Class
*/
SubGraphBase(std::shared_ptr<Manager> tm, unsigned int lookahead_ = 0) :
* @brief Constructor of NeuralNetwork Graph Class
* @param[in] enable_swap enable memory swap for tensor
* @param[in] mode execution mode (default ExecutionMode::TRAIN)
* @param[in] lookahead lookahead for swap (default 0)
* @param[in] tensor_format define tensor format. One of NCHW and NHWC
* (default NCHW)
* @param[in] tensor_type It says weight type and activation type (default
* FP32-FP32)
*/
SubGraphBase(std::shared_ptr<Manager> &tm,
ExecutionMode mode = ExecutionMode::TRAIN,
unsigned int lookahead = 0,
const std::string &tensor_format_ = "NCHW",
const std::string &tensor_dtype_ = "FP32-FP32") :
tensor_manager(tm),
subgraph(),
compiled(false),
Expand All @@ -55,10 +66,10 @@ class SubGraphBase : public GraphNode {
backward_iter_end(nullptr),
forward_iter_end(nullptr),
optimize_memory(true),
exec_mode(ExecutionMode::TRAIN),
tensor_format("NCHW"),
tensor_dtype(split("FP32-FP32", getRegex("\\-"))),
lookahead(lookahead_) {
exec_mode(mode),
tensor_format(tensor_format_),
tensor_dtype(split(tensor_dtype_, getRegex("\\-"))),
lookahead(lookahead) {
nan_count = 0;
}

Expand Down
18 changes: 14 additions & 4 deletions nntrainer/graph/subgraph_cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,21 @@ class SubGraphCpu : public SubGraphBase {

public:
/**
* @brief Constructor of NeuralNetwork SubGraph Class
* @brief Constructor of NeuralNetwork Graph Class
* @param[in] enable_swap enable memory swap for tensor
* @param[in] mode execution mode (default ExecutionMode::TRAIN)
* @param[in] lookahead lookahead for swap (default 0)
* @param[in] tensor_format define tensor format. One of NCHW and NHWC
* (default NCHW)
* @param[in] tensor_type It says weight type and activation type (default
* FP32-FP32)
*/
SubGraphCpu(std::shared_ptr<Manager> tm, unsigned int lookahead_ = 0) :
SubGraphBase(tm, lookahead_) {}

SubGraphCpu(std::shared_ptr<Manager> tm,
ExecutionMode mode = ExecutionMode::TRAIN,
unsigned int lookahead = 0,
const std::string &tensor_format_ = "NCHW",
const std::string &tensor_dtype_ = "FP32-FP32") :
SubGraphBase(tm, mode, lookahead, tensor_format_, tensor_dtype_) {}
/**
* @brief Destructor of the NeuralNetwork SubGraph class
*
Expand Down

0 comments on commit deeae64

Please sign in to comment.