{"id":307,"date":"2021-10-21T16:32:33","date_gmt":"2021-10-21T23:32:33","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/windowsai\/?p=307"},"modified":"2021-10-21T16:32:33","modified_gmt":"2021-10-21T23:32:33","slug":"introducing-pytorch-directml-train-your-machine-learning-models-on-any-gpu","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/windowsai\/introducing-pytorch-directml-train-your-machine-learning-models-on-any-gpu\/","title":{"rendered":"Introducing PyTorch-DirectML: Train your machine learning models on any GPU"},"content":{"rendered":"<p>The Windows AI team is excited to announce the first preview of DirectML as a backend to PyTorch for training ML models! This release is our first step towards unlocking accelerated machine learning training for PyTorch on any DirectX12 GPU on Windows and the Windows Subsystem for Linux (WSL).<\/p>\n<p>In order for you to take advantage of DirectML within PyTorch, today we are releasing a preview PyTorch-DirectML package, which provides scoped support for convolutional neural networks (CNNS). In this package, DirectML is integrated with the PyTorch framework by introducing a new device named \u201cDML,\u201d which calls on the DirectML APIs and PyTorch Tensor primitives. There is minimal overhead calling into the DirectML operators, and the DirectML backend works in the same way as other existing PyTorch backends. We co-engineered with AMD, Intel, and NVIDIA to enable this hardware accelerated training experience for PyTorch.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/windowsai\/wp-content\/uploads\/sites\/71\/2021\/10\/PyTorch-DirectML-Arc.png\"><img decoding=\"async\" class=\"aligncenter size-full wp-image-308\" src=\"https:\/\/devblogs.microsoft.com\/windowsai\/wp-content\/uploads\/sites\/71\/2021\/10\/PyTorch-DirectML-Arc.png\" alt=\"Image PyTorch DirectML Arc\" width=\"1477\" height=\"436\" \/><\/a><\/p>\n<p>The PyTorch-DirectML package is easy to install, and only requires changing one line of code in an existing script. To get started, you can install the package by calling:<\/p>\n<p><span style=\"font-family: 'andale mono', monospace;\">pip install pytorch-directml<\/span><\/p>\n<p>or download the package on <a href=\"https:\/\/pypi.org\/project\/PyTorch-DirectML\/\">PyPI<\/a>. In order to use the DirectML backend, the only code change necessary is to specify it by calling Torch.to(dml). See the code below for an example:<\/p>\n<p><span style=\"font-family: 'andale mono', monospace;\">a = torch.tensor([[1, 2, 3], [1, 2, 3]]).to(\u201cdml\u201d)<\/span><\/p>\n<p>That\u2019s it! You\u2019re all set to start running your PyTorch training scripts!<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Try it out and stay involved<\/strong><\/p>\n<p>We encourage you to try PyTorch-DirectML and give us feedback on how the DirectML backend is working for you!<\/p>\n<p>To help you get started, we created a tutorial for training SqueezeNet and ResNet on <a href=\"https:\/\/github.com\/microsoft\/DirectML\/tree\/master\/PyTorch\">GitHub<\/a>.<\/p>\n<p>Please leave questions, suggestions, or issues here on <a href=\"https:\/\/github.com\/microsoft\/DirectML\/issues\">GitHub<\/a>. Our team is constantly monitoring the community\u2019s feedback, and we look forward to hearing from you!<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The Windows AI team is excited to announce the first preview of DirectML as a backend to PyTorch for training ML models! This release is our first step towards unlocking accelerated machine learning training for PyTorch on any DirectX12 GPU on Windows and the Windows Subsystem for Linux (WSL). In order for you to take [&hellip;]<\/p>\n","protected":false},"author":60022,"featured_media":308,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-307","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-windows-ai"],"acf":[],"blog_post_summary":"<p>The Windows AI team is excited to announce the first preview of DirectML as a backend to PyTorch for training ML models! This release is our first step towards unlocking accelerated machine learning training for PyTorch on any DirectX12 GPU on Windows and the Windows Subsystem for Linux (WSL). In order for you to take [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/windowsai\/wp-json\/wp\/v2\/posts\/307","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/windowsai\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/windowsai\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/windowsai\/wp-json\/wp\/v2\/users\/60022"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/windowsai\/wp-json\/wp\/v2\/comments?post=307"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/windowsai\/wp-json\/wp\/v2\/posts\/307\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/windowsai\/wp-json\/wp\/v2\/media\/308"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/windowsai\/wp-json\/wp\/v2\/media?parent=307"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/windowsai\/wp-json\/wp\/v2\/categories?post=307"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/windowsai\/wp-json\/wp\/v2\/tags?post=307"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}