ATen .options() and .type()

What is the difference between .options() and .type()?

auto w  = at::empty({batches, channels, height, width}, xy.type());

vs

auto w  = at::empty({batches, channels, height, width}, xy.options());

Would they both inherit the same device from xy?

I asked a similar question earlier that I realized I can use .options.

According to the documentation, the options carry 4 construction axes: type, layout, device and requires_grad.

1 Like

don’t use type(), it’s deprecated.

1 Like

But does that mean type itself does not have device or layout? please note that type is different from dtype. I guess .type() is what now .options() provides with better details.

I have also lots of

AT_DISPATCH_FLOATING_TYPES(xy.type() ...)

should I update them as well?

Nope. Type is related to the numeric encoding of the tensor (i.e. int32, int64, float32, etc). Layout relates to the memory layout of your Tensor storage, it can be strided or sparse.

You should use AT_DISPATCH_FLOATING_TYPES(xy.scalar_type() ...) now.

2 Likes