MCPcopy Create free account
hub / github.com/cactus-compute/cactus / test_node_save_load

Function test_node_save_load

tests/test_graph.cpp:609–655  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

607}
608
609bool test_node_save_load() {
610 try {
611 CactusGraph graph;
612
613 size_t input_a = graph.input({2, 3}, Precision::FP16);
614 size_t input_b = graph.input({2, 3}, Precision::FP16);
615 size_t result_id = graph.add(input_a, input_b);
616
617 std::vector<__fp16> data_a = {1, 2, 3, 4, 5, 6};
618 std::vector<__fp16> data_b = {10, 20, 30, 40, 50, 60};
619
620 graph.set_input(input_a, const_cast<void*>(static_cast<const void*>(data_a.data())), Precision::FP16);
621 graph.set_input(input_b, const_cast<void*>(static_cast<const void*>(data_b.data())), Precision::FP16);
622 graph.execute();
623
624 std::string filename = "test_graph_save_load.bin";
625 GraphFile::save_node(graph, result_id, filename);
626
627 CactusGraph new_graph;
628 size_t loaded_id = new_graph.mmap_weights(filename);
629 new_graph.execute();
630
631 __fp16* original_data = static_cast<__fp16*>(graph.get_output(result_id));
632 __fp16* loaded_data = static_cast<__fp16*>(new_graph.get_output(loaded_id));
633
634 for (size_t i = 0; i < 6; ++i) {
635 if (std::abs(static_cast<float>(original_data[i]) - static_cast<float>(loaded_data[i])) > 1e-3f) {
636 graph.hard_reset();
637 new_graph.hard_reset();
638 std::remove(filename.c_str());
639 return false;
640 }
641 }
642
643 const auto& buf = new_graph.get_output_buffer(loaded_id);
644 bool result = (buf.shape == std::vector<size_t>{2, 3}) &&
645 (buf.precision == Precision::FP16) &&
646 (buf.byte_size == 12);
647
648 graph.hard_reset();
649 new_graph.hard_reset();
650 std::remove(filename.c_str());
651 return result;
652 } catch (const std::exception& e) {
653 return false;
654 }
655}
656
657
658bool test_graph_save_load() {

Callers 1

mainFunction · 0.85

Calls 10

save_nodeFunction · 0.85
dataMethod · 0.80
mmap_weightsMethod · 0.80
get_output_bufferMethod · 0.80
inputMethod · 0.45
addMethod · 0.45
set_inputMethod · 0.45
executeMethod · 0.45
get_outputMethod · 0.45
hard_resetMethod · 0.45

Tested by

no test coverage detected