@@ -324,7 +324,8 @@ Constant::Constant(const Constant& other)
324324 m_data{other.m_data },
325325 m_all_elements_bitwise_identical{other.m_all_elements_bitwise_identical .load ()},
326326 m_all_elements_bitwise_identical_checked{other.m_all_elements_bitwise_identical_checked .load ()},
327- m_alloc_buffer_on_visit_attributes{other.m_alloc_buffer_on_visit_attributes } {
327+ m_alloc_buffer_on_visit_attributes{other.m_alloc_buffer_on_visit_attributes },
328+ m_external_name{other.m_external_name } {
328329 constructor_validate_and_infer_types ();
329330}
330331
@@ -591,32 +592,46 @@ bool Constant::visit_attributes(AttributeVisitor& visitor) {
591592 OV_OP_SCOPE (v0_Constant_visit_attributes);
592593 const auto prev_shape = m_shape;
593594 const auto prev_type = m_element_type;
595+ const auto prev_external_name = m_external_name;
594596 visitor.on_attribute (" element_type" , m_element_type);
595597 visitor.on_attribute (" shape" , m_shape);
598+ visitor.on_attribute (" external_name" , m_external_name);
596599
597- const auto need_to_reallocate = (m_shape != prev_shape) || (prev_type != m_element_type);
598- const auto is_string_constant = (m_element_type == element::string);
599- if (m_alloc_buffer_on_visit_attributes && need_to_reallocate) {
600- // string objects initialization is required, others filling in a fresh constant
601- allocate_buffer (is_string_constant);
602- }
603-
604- if (is_string_constant) {
605- if (auto string_aligned_buffer = std::dynamic_pointer_cast<ov::StringAlignedBuffer>(m_data)) {
606- visitor.on_attribute (" value" , string_aligned_buffer);
607- } else if (auto shared_string_tensor = std::dynamic_pointer_cast<ov::SharedBuffer<ov::Tensor>>(m_data)) {
608- auto shared_string_buffer =
609- std::make_shared<ov::SharedStringAlignedBuffer>(shared_string_tensor->get_ptr <char >(),
610- shared_string_tensor->size ());
611- visitor.on_attribute (" value" , shared_string_buffer);
600+ if (!m_external_name.empty ()) {
601+ if (prev_external_name != m_external_name) {
602+ // If it becomes an external constant or change it's content, it is unlinked
603+ std::cerr << " [ DEBUG ] ExternalConstant in Constant::visit_attributes is activated" << std::endl;
604+ m_data.reset ();
612605 } else {
613- // deserialization case when buffer does not exist yet
614- std::shared_ptr<ov::StringAlignedBuffer> string_aligned_buffer;
615- visitor.on_attribute (" value" , string_aligned_buffer);
616- m_data = string_aligned_buffer;
606+ std::cerr << " [ DEBUG ] Retriving value from Constant::visit_attributes" << std::endl;
607+ std::cerr << " m_external_name = " << m_external_name << std::endl;
608+ std::cerr << " Skip value retrieving" << std::endl;
617609 }
618610 } else {
619- visitor.on_attribute (" value" , m_data);
611+ const auto need_to_reallocate = (m_shape != prev_shape) || (prev_type != m_element_type);
612+ const auto is_string_constant = (m_element_type == element::string);
613+ if (m_alloc_buffer_on_visit_attributes && need_to_reallocate) {
614+ // string objects initialization is required, others filling in a fresh constant
615+ allocate_buffer (is_string_constant);
616+ }
617+
618+ if (is_string_constant) {
619+ if (auto string_aligned_buffer = std::dynamic_pointer_cast<ov::StringAlignedBuffer>(m_data)) {
620+ visitor.on_attribute (" value" , string_aligned_buffer);
621+ } else if (auto shared_string_tensor = std::dynamic_pointer_cast<ov::SharedBuffer<ov::Tensor>>(m_data)) {
622+ auto shared_string_buffer =
623+ std::make_shared<ov::SharedStringAlignedBuffer>(shared_string_tensor->get_ptr <char >(),
624+ shared_string_tensor->size ());
625+ visitor.on_attribute (" value" , shared_string_buffer);
626+ } else {
627+ // deserialization case when buffer does not exist yet
628+ std::shared_ptr<ov::StringAlignedBuffer> string_aligned_buffer;
629+ visitor.on_attribute (" value" , string_aligned_buffer);
630+ m_data = string_aligned_buffer;
631+ }
632+ } else {
633+ visitor.on_attribute (" value" , m_data);
634+ }
620635 }
621636 update_identical_flags (false , false );
622637 return true ;
0 commit comments