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

#0: Port eltwise and some misc ops to use TensorSpec #15471

Merged
merged 3 commits into from
Nov 27, 2024

Conversation

sminakov-tt
Copy link
Contributor

@sminakov-tt sminakov-tt commented Nov 26, 2024

Ticket

Problem description

We need to migrate all ops to use compute_output_specs with TensorSpec, instead of older compute_output_shapes

What's changed

Migrated ops to TensorSpec:

  • binary
  • unary
  • bernoulli
  • embedding
  • embedding_backward
  • unifrorm

Fixes in the infrastructure to support the migration.

Checklist

  • Post commit CI passes
  • Blackhole Post commit (if applicable)
  • Model regression CI testing passes (if applicable)
  • Device performance regression CI testing passes (if applicable)
  • New/Existing tests provide coverage for changes

const auto& tensor_b = tensor_args.input_tensor_b;
const auto input_shape_b = tensor_b.has_value() ? tensor_b->shape() : ttnn::Shape{1, 1};
const auto input_shape_b = tensor_b.has_value() ? tensor_b->logical_shape() : ttnn::SimpleShape{};
Copy link
Member

Choose a reason for hiding this comment

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

Has value what does it mean?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

tensor_b is optional here. I'm unsure what it means for a binary op to have a second argument as optional, but preserving the behavior

Copy link
Member

Choose a reason for hiding this comment

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

I remember now. This is how float scalar is handled. Think of it like there is a union. It’s or float or tensor. Just expressed in this way

if (output_tensor.has_value()) {
return output_tensor.value();
}
auto output_shape = compute_broadcasted_output(input_shape_a, input_shape_b);

auto program_factory = select_program_factory(operation_attributes, tensor_args);
Copy link
Member

Choose a reason for hiding this comment

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

Got a bit surprised that we call this method here. It means we call it at least two times per operation call. Not that it’s a problem but it’s a surprise.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah. I would expect that select_program_factory should be really quick. It makes sense, at least to some extent, that the output tensor specs depend on the actual factory being used for these input arguments.

if (tensor_args.output_tensor.has_value()) {
return *tensor_args.output_tensor;
}
return create_device_tensor(compute_output_specs(operation_attributes, tensor_args), tensor_args.input_tensor_a.device());
Copy link
Member

Choose a reason for hiding this comment

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

So interesting. Tensor might have multiple devices today. I see this part of code did not change, but I wonder..

On this level multidevice basically does not exist today if I get it right.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. Multi-device seems to be problematic overall at the moment. With having single MeshDevice it should work as expected though.

Copy link
Member

@ayerofieiev-tt ayerofieiev-tt left a comment

Choose a reason for hiding this comment

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

Please link test runs.
Otherwise looks fine to me.
Left some comments they would be good to discuss but they are not related to this change.

Copy link
Contributor

@ntarafdar ntarafdar left a comment

Choose a reason for hiding this comment

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

I may have missed it but I don't see any padding calculations. Is this because none of these ops used the padded shape anywhere?

@sminakov-tt
Copy link
Contributor Author

@ntarafdar None of the ops did anything before to request a custom padding.
In general, at this moment, ops shouldn't think too much about the padding, unless they want something non-standard.

@ntarafdar
Copy link
Contributor

@sminakov-tt awesome. Ya next week I'm going to do the same for data movement ops. I think only transpose uses padding for anything so hoping it should be rather smooth for me as well!

@sminakov-tt sminakov-tt merged commit d9cc84c into main Nov 27, 2024
123 checks passed
@sminakov-tt sminakov-tt deleted the sminakov/tensorspec-1 branch November 27, 2024 19:29
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.

4 participants