Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the number of bytes commonly used by pytorch data types

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article introduces the knowledge of "how many bytes are occupied by pytorch common data types". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

The common data types on PyTorch are Data typedtypeCPU tensorGPU tensorSize/bytes32-bit floatingtorch.float32 or torch.floattorch.FloatTensortorch.cuda.FloatTensor464-bit floatingtorch.float64 or torch.doubletorch.DoubleTensortorch.cuda.DoubleTensor816-bit floatingtorch.float16or torch.halftorch.HalfTensortorch.cuda.HalfTensor-8-bit integer (unsigned) torch.uint8torch.ByteTensortorch.cuda.ByteTensor18-bit integer (signed) torch.int8torch.CharTensortorch.cuda.CharTensor-16-bit integer (signed) torch.int16or torch.shorttorch.ShortTensortorch.cuda.ShortTensor232-bit integer (signed) torch .int32 or torch.inttorch.IntTensortorch.cuda.IntTensor464-bit integer (signed) torch.int64 or torch.longtorch.LongTensortorch.cuda.LongTensor8

The data types in the above PyTorch correspond to those in numpy, and the occupied byte size is the same.

Add: pytorch tensor should pay attention to comparing large and small data types.

The following a = torch.tensor ([[0,0], [0,0]]) print (a > = 0.5)

Output

Tensor ([1,1]

[1,1]], dtype=torch.uint8)

The result is obviously wrong. The reason for the analysis is that an is of long type and 0.5 is float. 0. 5 will be converted to long, 0. 5%. Therefore, the result will go wrong, and the correct answer can be obtained by making the following changes.

Correct usage: a = torch.tensor ([[0,0], [0,0]]). Float () print (a > = 0.5) "how many bytes are occupied by common pytorch data types" is introduced here. Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report