Skip to content

Commit

Permalink
Fix a bug on simplify call.
Browse files Browse the repository at this point in the history
  • Loading branch information
liuliu committed Oct 9, 2023
1 parent da46ab5 commit a9772ed
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
6 changes: 3 additions & 3 deletions bin/nnc/wmt.c
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ static void eval_wmt(const int max_length, const int embedding_size, const char*
.dropout = 0.1,
};
ccv_cnnp_model_t* const wmt = ccv_cnnp_dynamic_new(_dynamic_encoder_decoder, &encoder_decoder_params, 0);
ccv_nnc_cmd_t adam = CMD_ADAM_FORWARD(1, 0.0001, 0.9, 0.98, 0, 1e-9);
ccv_nnc_cmd_t adam = CMD_ADAM_FORWARD(1, 0.0001, 0.9, 0.98, 0, 1e-9, 0);
ccv_nnc_tensor_param_t inputs[4];
inputs[0] = GPU_TENSOR_NCHW(000, 32F, 1, max_length, embedding_size);
inputs[1] = GPU_TENSOR_NCHW(000, 32F, 1, max_length, embedding_size);
Expand Down Expand Up @@ -491,7 +491,7 @@ static void train_wmt(const int epoch_limit, const int src_vocab_size, const int
ccv_cnnp_model_set_data_parallel(wmt, device_count);
const int epoch_end = (ccv_cnnp_dataframe_row_count(train_data) + device_count * batch_size - 1) / (device_count * batch_size);
ccv_cnnp_dataframe_shuffle(train_data);
ccv_nnc_cmd_t adam = CMD_ADAM_FORWARD(1, 0.0001, 0.9, 0.98, 0, 1e-9);
ccv_nnc_cmd_t adam = CMD_ADAM_FORWARD(1, 0.0001, 0.9, 0.98, 0, 1e-9, 0);
const int aux_size = ccv_nnc_minimizer_saved_aux_size(adam);
ccv_nnc_dynamic_graph_t* const dynamic_graph = ccv_nnc_dynamic_graph_new();
ccv_nnc_tensor_t* const seq_vec_ = ccv_nnc_tensor_new(0, CPU_TENSOR_NCHW(32F, max_length, embedding_size), 0);
Expand Down Expand Up @@ -783,7 +783,7 @@ static void train_wmt(const int epoch_limit, const int src_vocab_size, const int
if ((i + 1) % big_step == 0)
{
float learn_rate = 1. / sqrt_d_model * ccv_min(1. / sqrtf((i + 1) / big_step), (float)((i + 1) / big_step) / (sqrtf(warmup_steps) * warmup_steps));
adam = CMD_ADAM_FORWARD((i + 1) / big_step, learn_rate, 0.9, 0.98, 0, 1e-9);
adam = CMD_ADAM_FORWARD((i + 1) / big_step, learn_rate, 0.9, 0.98, 0, 1e-9, 0);
ccv_cnnp_model_set_minimizer(wmt, adam, 0, 0, 0);
for (j = 0; j < device_count; j++)
tvin[j * 2] = src_vocab_vec_grad[j], tvin[j * 2 + 1] = tgt_vocab_vec_grad[j], tvout[j * 2] = src_vocab_vec[j], tvout[j * 2 + 1] = tgt_vocab_vec[j];
Expand Down
10 changes: 9 additions & 1 deletion lib/nnc/ccv_cnnp_model.c
Original file line number Diff line number Diff line change
Expand Up @@ -269,14 +269,22 @@ static void _ccv_cnnp_model_compile(ccv_cnnp_model_t* const model, const ccv_nnc
}
const int output_size = model->output_size;
ccv_nnc_graph_exec_symbol_autogen(model->graph, 0, 0, CCV_NNC_AUTOGEN_ALL_EXECS | CCV_NNC_AUTOGEN_SOURCES_AND_DESTINATIONS);
const int parameters_rnum = parameters->rnum;
if (input_size > 0)
{
ccv_array_resize(parameters, parameters_rnum + input_size);
memcpy(ccv_array_get(parameters, parameters_rnum), model->inputs, input_size * sizeof(ccv_nnc_tensor_symbol_t));
}
ccv_nnc_symbolic_graph_simplify(model->graph,
SYMBOLIC_GRAPH_PASSES(CCV_NNC_SIMPLIFY_COMMON_SUBEXPRESSION_ELIMINATION,
CCV_NNC_SIMPLIFY_DATA_TRANSFER_OPT,
CCV_NNC_SIMPLIFY_OPS_FUSION,
CCV_NNC_SIMPLIFY_GRAPH_PRUNING),
model->inputs, input_size,
ccv_array_get(parameters, 0), parameters_rnum + input_size,
model->outputs, output_size,
SYMBOLIC_GRAPH_SOURCES(model->graph), SYMBOLIC_GRAPH_DESTINATIONS(model->graph));
// Size it down.
parameters->rnum = parameters_rnum;
ccv_cnnp_compiled_data_t* compiled_data = model->compiled_data = cccalloc(1, sizeof(ccv_cnnp_compiled_data_t) + sizeof(ccv_nnc_tensor_symbol_t) * (output_size * 2 - 1));
_ccv_cnnp_compiled_data_init(compiled_data, output_size);
const int evaluate_to_size = compiled_data->evaluate.to_size = ccv_nnc_symbolic_graph_destination_size(model->graph);
Expand Down

0 comments on commit a9772ed

Please sign in to comment.