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

[onert] Separate forward and backward configuration of trainable ops #13033

Merged

Conversation

mbencer
Copy link
Contributor

@mbencer mbencer commented May 21, 2024

This PR separates forward and backward configuration of trainable ops in order to make possible disabling backward propagation of particular ops.

ONE-DCO-1.0-Signed-off-by: Mateusz Bencer m.bencer@partner.samsung.com

Draft: #12951
Issue: #12386

This PR separates forward and backward configuration of trainable ops
in order to make possible disabling backward propagation of particular ops.

ONE-DCO-1.0-Signed-off-by: Mateusz Bencer <m.bencer@partner.samsung.com>
fn->configure(input_tensor, output_tensor, back_prop_input_tensor, back_prop_output_tensor,
node.param().alpha, node.param().beta,
convertElementwiseActivationType(node.param().op_type));
auto convertToInferActivationType = [](const ir::operation::ElementwiseActivation::Type &type) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't alpha also be considered?

  switch (op_type)
  {
    case ElementwiseActivationType::kReLU:
... 
        if ((alpha == std::numeric_limits<float>::infinity() || alpha == 6.0f) && beta == 0.f)
        {
          cpu::ops::ElementwiseActivationLayer::configure(
            input, output, alpha, beta, cpu::ops::ElementwiseActivationType::kReLU);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's already checked inside ElementwiseActivationLayer::configureBackward (

if ((alpha == std::numeric_limits<float>::infinity() || alpha == 6.0f) && beta == 0.f)
).
Do you prefer to have it also here?

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, the alpha is not an issue. Why do you define the convertToInferActivationType function again? Can't use convertElementwiseActivationType function?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here we're converting ir::operation::ElementwiseActivation::Type to cpu::ops::ElementwiseActivationType while convertElementwiseActivationType returns train::ops::ElementwiseActivationType. In the previous version this conversion has been made impicitly (

switch (op_type)
{
case ElementwiseActivationType::kReLU:
if (input->data_type() == OperandType::FLOAT32)
{
if ((alpha == std::numeric_limits<float>::infinity() || alpha == 6.0f) && beta == 0.f)
{
cpu::ops::ElementwiseActivationLayer::configure(
input, output, alpha, beta, cpu::ops::ElementwiseActivationType::kReLU);
). But in general I agree that it will be great to introduce some unification of enum types or at least store helpers function in a one place.

Copy link
Contributor

Choose a reason for hiding this comment

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

I understand. The train Kernel generator selectively calls the cpu and train configuration functions according to the op.isRequiredForBackward() value. In order to support this, these changes should be implmenet in the KernelGenerator. So, the activation type has to be converted to the cpu and train types depending on the situation.

@mbencer mbencer requested a review from jyoungyun May 23, 2024 05:55
Copy link
Contributor

@jyoungyun jyoungyun left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@ragmani ragmani left a comment

Choose a reason for hiding this comment

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

LGTM

@zetwhite
Copy link
Contributor

Sorry for being late, I'm reading the code, right now.

Copy link
Contributor

@zetwhite zetwhite left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@hseok-oh hseok-oh merged commit 7ed4117 into Samsung:master May 27, 2024
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants