

{"id":108152,"date":"2022-03-10T09:00:57","date_gmt":"2022-03-10T03:30:57","guid":{"rendered":"https:\/\/data-flair.training\/blogs\/?p=108152"},"modified":"2022-03-10T09:58:24","modified_gmt":"2022-03-10T04:28:24","slug":"pytorch-packages","status":"publish","type":"post","link":"https:\/\/data-flair.training\/blogs\/pytorch-packages\/","title":{"rendered":"PyTorch Packages"},"content":{"rendered":"<p>PyTorch is a Deep Learning library that has several libraries dedicated to different purposes. The most important of them is torch.nn which helps us create neural layers. Other libraries such as torch.nn.functional, torch.optim, torch.Tensor etc are also very useful and supplement our neural networks to build a complete model. We will now take a look at some important packages of PyTorch.<\/p>\n<h3>PyTorch Packages<\/h3>\n<h4>1. torch:<\/h4>\n<p>It is the most basic package of PyTorch which contains data structures to accommodate tensors and allows us to perform operations on them.<\/p>\n<h4>2. torch.nn:<\/h4>\n<p>The module torch.nn forms the backbone of PyTorch as it provides most of the essential libraries required for Deep Learning like the convolution layers, linear layers, different activation functions, pooling layers, loss functions and many more.<\/p>\n<h4>3. torch.nn.functional:<\/h4>\n<p>torch.nn contains object oriented libraries but torch.nn.functional contains the same features but in function form, i.e they can be invoked like other functions.<\/p>\n<h4>4. torch.Tensor:<\/h4>\n<p>Tensors are multidimensional arrays containing values of the same data types. torch.Tensor contains various methods to perform tensor operations in one line which would otherwise take some effort.<\/p>\n<h4>5. torch.cuda:<\/h4>\n<p>Cuda is a parallel computing platform that allows us to utilise GPUs for our models. And as we know PyTorch owes its fast performance to GPUs. torch.cuda enables the transformation of tensors into GPU readable form.<\/p>\n<h4>6. torch.distributions:<\/h4>\n<p>It contains the parameterized probability function of the samples allowing the construction of dynamic computation graphs.<\/p>\n<h4>7. torch.fft:<\/h4>\n<p>Contains functions related to discrete fast fourier transforms.<\/p>\n<h4>8. torch.fx:<\/h4>\n<p>Provides toolkits to transform nn.Module instances.<\/p>\n<h4>9. torch.jit:<\/h4>\n<p>Jit takes PyTorch codes and converts it to C++ script which runs faster than Python codes.<\/p>\n<h4>10. torch.linalg:<\/h4>\n<p>Enables us to perform common linear algebra operations such as finding norm, inverse, transpose of a matrix etc.<\/p>\n<h4>11. torch.special:<\/h4>\n<p>It is a scientific library inspired by the SciPy library. It enables us to perform many scientific tasks like calculating entropy, gamma function etc.<\/p>\n<h4>12. torch.package:<\/h4>\n<p>Using torch.package we can create our own PyTorch package of the code which can be used whenever required.<\/p>\n<h4>13. torch.profiler:<\/h4>\n<p>It helps us better understand the process we are executing by collecting the performance metrics during training.<\/p>\n<h4>14. torch.onnx:<\/h4>\n<p>Facilitates exporting our machine learning models to ONNX (Open Neural Network Exchange).<\/p>\n<h4>15. torch.optim:<\/h4>\n<p>One of the most important libraries which helps us optimise our model. Using torch.optim we can also set the gradient to zero before each epoch, which is very crucial for obtaining meaningful results.<\/p>\n<h4>16. torch.random:<\/h4>\n<p>Deals with initialising our tensors with random numbers along with other related operations like setting the seed, generator state etc.<\/p>\n<h4>17. torch.sparse:<\/h4>\n<p>The tensors of the datasets of deep learning models sometimes contain mostly zeros leading to wastage of storage to store them. Sparse array allows us to store only non-zero elements thereby saving storage space.<\/p>\n<h4>18. torch.storage:<\/h4>\n<p>PyTorch tensors occupy contiguous memory space irrespective of the dimensionality which can be managed by torch.tensors.<\/p>\n<h4>19. torch.testing:<\/h4>\n<p>Indicates the distance between the actual and expected outputs to determine accuracy. This module is still in prototype state.<\/p>\n<h4>20. torch.utils.benchmark:<\/h4>\n<p>Provides time measuring tools for checking the running time of our model.<\/p>\n<h4>21. torch.utils.checkpoint:<\/h4>\n<p>Instead of saving all the computational graphs we can save only some essential graphs called checkpoint.<\/p>\n<h4>22. torch.utils.data:<\/h4>\n<p>Contains libraries like datasets and dataloaders which have some pre-processed data and an iterable that wraps around the available data respectively.<\/p>\n<h4>23. torch.utils.dlpack:<\/h4>\n<p>It is used to convert a tensor from an external source to PyTorch tensor.<\/p>\n<h3>Summary:<\/h3>\n<p>Owing to its variety and quantity of packages, PyTorch becomes very powerful in designing neural networks and comfortable even for beginners.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>PyTorch is a Deep Learning library that has several libraries dedicated to different purposes. The most important of them is torch.nn which helps us create neural layers. Other libraries such as torch.nn.functional, torch.optim, torch.Tensor&#46;&#46;&#46;<\/p>\n","protected":false},"author":5,"featured_media":108181,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[26498],"tags":[26680],"class_list":["post-108152","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-pytorch-tutorials","tag-pytorch-packages"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.0 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>PyTorch Packages - DataFlair<\/title>\n<meta name=\"description\" content=\"Learn about some of the top useful packages of PyTorch like torch, torch.nn, torch.nn.functional, torch.utils.dlpack, torch.utils.data etc\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/data-flair.training\/blogs\/pytorch-packages\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"PyTorch Packages - DataFlair\" \/>\n<meta property=\"og:description\" content=\"Learn about some of the top useful packages of PyTorch like torch, torch.nn, torch.nn.functional, torch.utils.dlpack, torch.utils.data etc\" \/>\n<meta property=\"og:url\" content=\"https:\/\/data-flair.training\/blogs\/pytorch-packages\/\" \/>\n<meta property=\"og:site_name\" content=\"DataFlair\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/DataFlairWS\/\" \/>\n<meta property=\"article:published_time\" content=\"2022-03-10T03:30:57+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-03-10T04:28:24+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/03\/pytorch-packages.webp\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/webp\" \/>\n<meta name=\"author\" content=\"DataFlair Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:site\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"DataFlair Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"PyTorch Packages - DataFlair","description":"Learn about some of the top useful packages of PyTorch like torch, torch.nn, torch.nn.functional, torch.utils.dlpack, torch.utils.data etc","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/data-flair.training\/blogs\/pytorch-packages\/","og_locale":"en_US","og_type":"article","og_title":"PyTorch Packages - DataFlair","og_description":"Learn about some of the top useful packages of PyTorch like torch, torch.nn, torch.nn.functional, torch.utils.dlpack, torch.utils.data etc","og_url":"https:\/\/data-flair.training\/blogs\/pytorch-packages\/","og_site_name":"DataFlair","article_publisher":"https:\/\/www.facebook.com\/DataFlairWS\/","article_published_time":"2022-03-10T03:30:57+00:00","article_modified_time":"2022-03-10T04:28:24+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/03\/pytorch-packages.webp","type":"image\/webp"}],"author":"DataFlair Team","twitter_card":"summary_large_image","twitter_creator":"@DataFlairWS","twitter_site":"@DataFlairWS","twitter_misc":{"Written by":"DataFlair Team","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/data-flair.training\/blogs\/pytorch-packages\/#article","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/pytorch-packages\/"},"author":{"name":"DataFlair Team","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/7f83c342f5d1632d6f7b4b0b0f447823"},"headline":"PyTorch Packages","datePublished":"2022-03-10T03:30:57+00:00","dateModified":"2022-03-10T04:28:24+00:00","mainEntityOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/pytorch-packages\/"},"wordCount":619,"commentCount":0,"publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/pytorch-packages\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/03\/pytorch-packages.webp","keywords":["PyTorch Packages"],"articleSection":["PyTorch Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/data-flair.training\/blogs\/pytorch-packages\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/data-flair.training\/blogs\/pytorch-packages\/","url":"https:\/\/data-flair.training\/blogs\/pytorch-packages\/","name":"PyTorch Packages - DataFlair","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/#website"},"primaryImageOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/pytorch-packages\/#primaryimage"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/pytorch-packages\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/03\/pytorch-packages.webp","datePublished":"2022-03-10T03:30:57+00:00","dateModified":"2022-03-10T04:28:24+00:00","description":"Learn about some of the top useful packages of PyTorch like torch, torch.nn, torch.nn.functional, torch.utils.dlpack, torch.utils.data etc","breadcrumb":{"@id":"https:\/\/data-flair.training\/blogs\/pytorch-packages\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/data-flair.training\/blogs\/pytorch-packages\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/pytorch-packages\/#primaryimage","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/03\/pytorch-packages.webp","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/03\/pytorch-packages.webp","width":1200,"height":628,"caption":"pytorch packages"},{"@type":"BreadcrumbList","@id":"https:\/\/data-flair.training\/blogs\/pytorch-packages\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog Home","item":"https:\/\/data-flair.training\/blogs\/"},{"@type":"ListItem","position":2,"name":"PyTorch Tutorials","item":"https:\/\/data-flair.training\/blogs\/category\/pytorch-tutorials\/"},{"@type":"ListItem","position":3,"name":"PyTorch Packages"}]},{"@type":"WebSite","@id":"https:\/\/data-flair.training\/blogs\/#website","url":"https:\/\/data-flair.training\/blogs\/","name":"DataFlair","description":"Learn Today. Lead Tomorrow.","publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/data-flair.training\/blogs\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/data-flair.training\/blogs\/#organization","name":"DataFlair","url":"https:\/\/data-flair.training\/blogs\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","width":106,"height":48,"caption":"DataFlair"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/DataFlairWS\/","https:\/\/x.com\/DataFlairWS","https:\/\/www.linkedin.com\/company\/dataflair-web-services-pvt-ltd\/","https:\/\/www.youtube.com\/user\/DataFlairWS"]},{"@type":"Person","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/7f83c342f5d1632d6f7b4b0b0f447823","name":"DataFlair Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/4cf3a74600d131330b8c481d519afd1574093ed89f6d3396a95393ad223eb7cd?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/4cf3a74600d131330b8c481d519afd1574093ed89f6d3396a95393ad223eb7cd?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/4cf3a74600d131330b8c481d519afd1574093ed89f6d3396a95393ad223eb7cd?s=96&d=mm&r=g","caption":"DataFlair Team"},"description":"DataFlair Team creates expert-level guides on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. Our goal is to empower learners with easy-to-understand content. Explore our resources for career growth and practical learning.","url":"https:\/\/data-flair.training\/blogs\/author\/dfteam1\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/108152","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/comments?post=108152"}],"version-history":[{"count":2,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/108152\/revisions"}],"predecessor-version":[{"id":108182,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/108152\/revisions\/108182"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media\/108181"}],"wp:attachment":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media?parent=108152"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/categories?post=108152"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/tags?post=108152"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}