Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GPU] LSTMSequence and LSTMCell optimization #26767

Open
wants to merge 117 commits into
base: master
Choose a base branch
from

Conversation

michal-miotk
Copy link
Contributor

@michal-miotk michal-miotk commented Sep 24, 2024

Details:

  • creating simple primitive for lstm_sequence to be faster than previous approach using many primitives
  • using oneDNN
  • based on commit c99ddc0 from 25732

Tickets:

  • 146601

commit 232d272f11fbe65e82fa9787260a8b9d34b57d20
Author: michal-miotk <michal.miotk@intel.com>
Date:   Mon Jul 29 11:17:47 2024 +0000

    wip

commit e642ca3
Author: michal-miotk <michal.miotk@intel.com>
Date:   Sun Jul 28 22:08:24 2024 +0000

    wip

commit c6b74d3
Author: michal-miotk <michal.miotk@intel.com>
Date:   Fri Jul 26 14:10:26 2024 +0000

    wip

commit 0451429
Author: michal-miotk <michal.miotk@intel.com>
Date:   Thu Jul 25 20:35:11 2024 +0000

    wip3
commit 1164592
Author: michal-miotk <michal.miotk@intel.com>
Date:   Tue Aug 6 09:25:45 2024 +0000

    wip

commit 8b2c049
Author: michal-miotk <michal.miotk@intel.com>
Date:   Tue Aug 6 09:24:02 2024 +0000

    wip

commit 886b412
Author: michal-miotk <michal.miotk@intel.com>
Date:   Mon Aug 5 14:59:14 2024 +0000

    wip

commit 08fb207
Author: michal-miotk <michal.miotk@intel.com>
Date:   Sun Aug 4 20:21:38 2024 +0000

    wip, errors on half

commit 125884d
Author: michal-miotk <michal.miotk@intel.com>
Date:   Sat Aug 3 23:59:58 2024 +0000

    wip

commit af4f209
Author: michal-miotk <michal.miotk@intel.com>
Date:   Fri Aug 2 17:58:38 2024 +0000

    wip

commit 12626fc
Author: michal-miotk <michal.miotk@intel.com>
Date:   Fri Aug 2 10:52:15 2024 +0000

    wip

commit dfdd052
Author: michal-miotk <michal.miotk@intel.com>
Date:   Thu Aug 1 15:38:41 2024 +0000

    wip

commit 54ee912
Author: michal-miotk <michal.miotk@intel.com>
Date:   Thu Aug 1 11:01:55 2024 +0000

    only bfyx layout

commit 240fe4a
Author: michal-miotk <michal.miotk@intel.com>
Date:   Thu Aug 1 10:34:45 2024 +0000

    two outputs from prim

commit bc775be
Author: michal-miotk <michal.miotk@intel.com>
Date:   Wed Jul 31 22:13:14 2024 +0000

    wip

commit d1cfd60
Author: michal-miotk <michal.miotk@intel.com>
Date:   Wed Jul 31 22:07:06 2024 +0000

    wip

commit 7d18884
Author: michal-miotk <michal.miotk@intel.com>
Date:   Wed Jul 31 19:19:04 2024 +0000

    begin of handling reverse

commit 39f64af
Author: michal-miotk <michal.miotk@intel.com>
Date:   Wed Jul 31 15:37:06 2024 +0000

    betterbetter

commit 67b3c9a
Author: michal-miotk <michal.miotk@intel.com>
Date:   Wed Jul 31 13:12:39 2024 +0000

    better

commit 6ded5aa
Author: michal-miotk <michal.miotk@intel.com>
Date:   Wed Jul 31 10:12:31 2024 +0000

    wip

commit 1ccdacc
Author: michal-miotk <michal.miotk@intel.com>
Date:   Tue Jul 30 23:07:21 2024 +0000

    wip

commit ab1307c
Author: michal-miotk <michal.miotk@intel.com>
Date:   Tue Jul 30 22:00:50 2024 +0000

    test passed

commit bc65969
Author: michal-miotk <michal.miotk@intel.com>
Date:   Tue Jul 30 15:37:20 2024 +0000

    wip

commit 03cbf57
Author: michal-miotk <michal.miotk@intel.com>
Date:   Tue Jul 30 15:15:06 2024 +0000

    only 2 outputs

commit fd5f3dc
Author: michal-miotk <michal.miotk@intel.com>
Date:   Tue Jul 30 14:47:12 2024 +0000

    wip

commit 939d23c
Author: michal-miotk <michal.miotk@intel.com>
Date:   Tue Jul 30 11:34:56 2024 +0000

    wip

commit 2bb561f
Author: michal-miotk <michal.miotk@intel.com>
Date:   Tue Jul 30 09:28:03 2024 +0000

    added to binary buffer

commit 1ef83ff
Author: michal-miotk <michal.miotk@intel.com>
Date:   Mon Jul 29 22:30:57 2024 +0000

    not works
@github-actions github-actions bot added the category: IE Tests OpenVINO Test: plugins and common label Oct 14, 2024
@@ -45,6 +45,7 @@ struct program {
friend class reorder_inputs; // to be removed when possible
friend class remove_redundant_reorders; // to be removed when possible
friend class post_optimize_weights; // to be removed when possible
friend class post_optimize_lstm_weights_and_output; // to be removed when possible
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: alignment

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

struct RNNParams{
RNNParams() = default;
RNNParams(const RNNParams&) = default;
RNNParams(const primitive_id& id,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why isn't primitive_base used as the base class?

primitive_id id;
input_info x;
input_info initial_hidden_state;
input_info initial_cell_state;/// @brief for lstm_elt primitive field for cell input_info
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: please, fix @brief location

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


// function which prepares given primitive for weights optimization
template<typename T>
void post_optimize_lstm_weights_and_output::optimize_lstm_weights(T& node, program& p) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couldn't this be implemented as part of post_optimize_weights::optimize_weights?
It looks like a lot of code should match

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

if (!primitive->params.activations.empty()) {
auto a_sz = primitive->params.activations.size();
auto param_sz = primitive->params.activation_params.size();
OPENVINO_ASSERT(param_sz == 0|| a_sz == param_sz, "[GPU] Unexpected activation params count in lstm_cell impl: ", param_sz);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit:

Suggested change
OPENVINO_ASSERT(param_sz == 0|| a_sz == param_sz, "[GPU] Unexpected activation params count in lstm_cell impl: ", param_sz);
OPENVINO_ASSERT(param_sz == 0 || a_sz == param_sz, "[GPU] Unexpected activation params count in lstm_cell impl: ", param_sz);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment on lines 38 to 39
return {cldnn::layout{ShapeType{lstm_batch_size, lstm_hidden_size}, input_layout_x.data_type, input_layout_x.format}, \
cldnn::layout{ShapeType{lstm_batch_size, lstm_hidden_size}, input_layout_x.data_type, input_layout_x.format}};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return {cldnn::layout{ShapeType{lstm_batch_size, lstm_hidden_size}, input_layout_x.data_type, input_layout_x.format}, \
cldnn::layout{ShapeType{lstm_batch_size, lstm_hidden_size}, input_layout_x.data_type, input_layout_x.format}};
auto out_layout = cldnn::layout{ShapeType{lstm_batch_size, lstm_hidden_size}, input_layout_x.data_type, input_layout_x.format};
return {out_layout, out_layout };

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

#ifdef SEQUENCE
INPUT1_TYPE_VEC initial_block = READ_VEC(0, &initial_hidden_state[INPUT1_GET_INDEX(b, 0, j*VEC_SIZE, 0)]);
INPUT4_TYPE_VEC r_block = READ_VEC(0, &R[INPUT4_GET_INDEX(0, weight_idx, j*VEC_SIZE, 0)]);
hidden_result += initial_block.s0*r_block.s0 + initial_block.s1*r_block.s1 + initial_block.s2*r_block.s2 + initial_block.s3*r_block.s3 + initial_block.s4*r_block.s4 + initial_block.s5*r_block.s5 + initial_block.s6*r_block.s6 + initial_block.s7*r_block.s7;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Maybe some macro can reduce the length of a line of similar operations

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

k.EnableTensorOffset();
k.EnableTensorPitches();
k.EnableBatching();
k.EnableDynamicShapesSupport();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there support for dynamic shapes?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


auto inputs = p.GetInputInfo(op);
/*
if (op->get_input_shape(2).size() != 2 || op->get_input_shape(3).size() != 2 \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this check no longer valid?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

cldnn::input_info(), "", "", clip, activations, \
activation_params, cldnn::lstm_weights_order::fizo, direction, cldnn::padding(), \
static_cast<int>(op->get_output_size())}, 0);
//prim.output_data_types = get_output_data_types(op);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commented code

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category: build OpenVINO cmake script / infra category: GPU OpenVINO GPU plugin category: IE Tests OpenVINO Test: plugins and common
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants