{"id":216,"date":"2024-09-30T23:48:59","date_gmt":"2024-09-30T15:48:59","guid":{"rendered":"https:\/\/blog.faspand.top\/?p=216"},"modified":"2024-09-30T23:48:59","modified_gmt":"2024-09-30T15:48:59","slug":"wsl2cudapycharm%e6%90%ad%e5%bb%bapytorch%e7%8e%af%e5%a2%83","status":"publish","type":"post","link":"https:\/\/blog.faspand.top\/index.php\/2024\/09\/30\/wsl2cudapycharm%e6%90%ad%e5%bb%bapytorch%e7%8e%af%e5%a2%83\/","title":{"rendered":"WSL2+CUDA+PyCharm\u642d\u5efaPyTorch\u73af\u5883"},"content":{"rendered":"<h1>\u5e8f<\/h1>\n<p>\u56fd\u5e86\u95f2\u6765\u65e0\u4e8b\uff0c\u51b3\u5b9a\u81ea\u5df1\u5b9e\u9645\u64cd\u4f5c\u4e00\u4e0b\u3002\u9996\u5148\u8981\u5b8c\u6210\u7684\u4efb\u52a1\u5c31\u662f\u73af\u5883\u642d\u5efa\u3002\u672c\u6559\u7a0b\u662fNvdia\u72ec\u663e+Windows\u7535\u8111+WSL2\u73af\u5883\u4e0b\u7684PyTorch\u5b89\u88c5\u4ee5\u53ca\u4f7f\u7528PyCharm\u8fde\u63a5\u73af\u5883<\/p>\n<h1>\u5b89\u88c5<\/h1>\n<h2>\u5b89\u88c5Miniconda<\/h2>\n<p>\u6700\u7b80\u5355\u7684\u65b9\u6cd5\u5c31\u662f\u5b89\u88c5\u4f9d\u8d56Python 3.x\u7684<a href=\"https:\/\/conda.io\/en\/latest\/miniconda.html\">Miniconda<\/a>\u3002 \u5982\u679c\u5df2\u5b89\u88c5conda\uff0c\u5219\u53ef\u4ee5\u8df3\u8fc7\u4ee5\u4e0b\u6b65\u9aa4\u3002\u8bbf\u95eeMiniconda\u7f51\u7ad9\uff0c\u6839\u636ePython3.x\u7248\u672c\u786e\u5b9a\u9002\u5408\u7684\u7248\u672c\u3002<\/p>\n<p>\u5bf9\u4e8e64\u4f4d\u5143\u7684Linux\u4f5c\u4e1a\u7cfb\u7edf\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u5b98\u65b9\u63d0\u4f9b\u7684\u6307\u4ee4\uff1a<\/p>\n<pre><code class=\"language-bash\">mkdir -p ~\/miniconda3\nwget https:\/\/repo.anaconda.com\/miniconda\/Miniconda3-latest-Linux-x86_64.sh -O ~\/miniconda3\/miniconda.sh\nbash ~\/miniconda3\/miniconda.sh -b -u -p ~\/miniconda3\nrm ~\/miniconda3\/miniconda.sh<\/code><\/pre>\n<p>\u521d\u59cb\u5316\u73af\u5883<\/p>\n<pre><code class=\"language-bash\">~\/miniconda3\/bin\/conda init<\/code><\/pre>\n<p>\u521d\u59cb\u5316\u5b8c\u6210\u540e\uff0c\u63d0\u793a\u5173\u95ed\u5f53\u524d\u7ec8\u7aef\uff0c\u91cd\u65b0\u6253\u5f00\u65b0\u7684\u7ec8\u7aef<\/p>\n<p>\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u73af\u5883\uff0c\u5176\u540d\u79f0\u53ef\u4ee5\u4fee\u6539\uff1a<\/p>\n<pre><code class=\"language-bash\">conda create --name d2l python=3.9 -y<\/code><\/pre>\n<p>\u5207\u6362\u5230d2l\u73af\u5883<\/p>\n<pre><code class=\"language-bash\">conda activate d2l<\/code><\/pre>\n<p>\u6ce8\u610f\u6bcf\u6b21\u8fd0\u884c\u90fd\u8981\u8fd0\u884c\u6b64\u6307\u4ee4\u3002\u4f8b\u5982\u6bcf\u6b21<code>source .bashrc<\/code> \u4e4b\u540e\u3002<\/p>\n<p>\u5982\u8981\u9000\u51fa\u5f53\u524d\u73af\u5883\uff1a<code>conda deactivate<\/code>\u3002<br \/>\n\u5982\u8981\u5b8c\u6574\u5220\u9664\u540d\u4e3a<strong>dal<\/strong>\u7684\u73af\u5883\uff1a<code>conda remove -n d2l --all<\/code><\/p>\n<h2>\u5b89\u88c5CUDA<\/h2>\n<p>CUDA<a href=\"https:\/\/developer.nvidia.com\/cuda-downloads?target_os=Linux&amp;target_arch=x86_64&amp;Distribution=WSL-Ubuntu&amp;target_version=2.0&amp;target_type=deb_local\">(\u5b98\u7f51)<\/a>\u662f\u82f1\u4f1f\u8fbe\u5b98\u65b9\u7684\u6df1\u5ea6\u5b66\u4e60\u5de5\u5177\u5305\uff0c\u5982\u56fe\u662fWSL\u7684\u9009\u9879\u3002\u8fd0\u884c\u4e0b\u8f7d\u4ee3\u7801\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/img.nozomicloud.top\/\/blog\/article\/image-20240930231219011.png\" alt=\"image-20240930231219011\" \/><\/p>\n<pre><code class=\"language-bash\">wget https:\/\/developer.download.nvidia.com\/compute\/cuda\/repos\/wsl-ubuntu\/x86_64\/cuda-wsl-ubuntu.pin\nsudo mv cuda-wsl-ubuntu.pin \/etc\/apt\/preferences.d\/cuda-repository-pin-600\nwget https:\/\/developer.download.nvidia.com\/compute\/cuda\/12.6.1\/local_installers\/cuda-repo-wsl-ubuntu-12-6-local_12.6.1-1_amd64.deb\nsudo dpkg -i cuda-repo-wsl-ubuntu-12-6-local_12.6.1-1_amd64.deb\nsudo cp \/var\/cuda-repo-wsl-ubuntu-12-6-local\/cuda-*-keyring.gpg \/usr\/share\/keyrings\/\nsudo apt-get update\nsudo apt-get -y install cuda-toolkit-12-6<\/code><\/pre>\n<p>\u4ece\u5b98\u7f51\u5b89\u88c5\u7684CUDA\u8c8c\u4f3c\u9700\u8981\u624b\u52a8\u8bbe\u7f6e\u73af\u5883\u53d8\u91cf<\/p>\n<pre><code class=\"language-bash\">sudo vi ~\/.bashrc\nconda activate d2l<\/code><\/pre>\n<p><code>i<\/code>\u8fdb\u5165insert\u6a21\u5f0f\uff0c\u6dfb\u52a0\u4ee5\u4e0b\u4ee3\u7801\u5230\u6587\u4ef6\u6700\u540e\uff0c\u6ce8\u610f\u4fee\u6539\u4e3a\u5bf9\u5e94\u7248\u672c\uff0c\u6b64\u5904\u4f7f\u7528cuda12.1\u3002<\/p>\n<pre><code class=\"language-bash\">export PATH=\/usr\/local\/cuda-12.1\/bin${PATH:+:${PATH}}\nexport LD_LIBRARY_PATH=\/usr\/local\/cuda-12.1\/lib64\\${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}<\/code><\/pre>\n<p><code>Esc<\/code>, <code>:wq<\/code>\uff0c\u56de\u8f66\u4fdd\u5b58\u3002<\/p>\n<pre><code class=\"language-bash\">source ~\/.bashrc\nconda activate d2l<\/code><\/pre>\n<h2>\u6d4b\u8bd5<\/h2>\n<p>\u5728\u7ec8\u7aef\u4e2d\u6267\u884c<code><code> nvcc -V<\/code><\/code>\uff0c\u82e5\u5b89\u88c5\u6210\u529f\uff0c\u5e94\u8f93\u51fa\uff1a<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/img.nozomicloud.top\/\/blog\/article\/image-20240930231618394.png\" alt=\"image-20240930231618394\" \/><\/p>\n<p>\u6267\u884c<code><code>nvidia-smi<\/code><\/code>\uff0c\u5e94\u8f93\u51fa\u5f53\u524d\u8bbe\u5907\u4fe1\u606f\uff1a<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/img.nozomicloud.top\/\/blog\/article\/image-20240930231732593.png\" alt=\"image-20240930231732593\" \/><\/p>\n<h2>\u5b89\u88c5PyTorch<\/h2>\n<p>\u5728<a href=\"https:\/\/pytorch.org\/get-started\/locally\/\">PyTorch\u5b98\u7f51<\/a>\u9009\u62e9\u5408\u9002\u7248\u672c\uff0cCUDA\u7248\u672c\u53ef\u5411\u4e0b\u517c\u5bb9\u3002<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/img.nozomicloud.top\/\/blog\/article\/image-20240930231856110.png\" alt=\"image-20240930231856110\" \/><\/p>\n<p>\u786e\u4fdd\u6307\u4ee4\u5728d2l\u73af\u5883\u4e0b\u8fd0\u884c.<\/p>\n<h1>PyCharm\u8fde\u63a5WSL<\/h1>\n<p>\u65b0\u5efa\u4e00\u4e2aInterpreter On WSL<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/img.nozomicloud.top\/\/blog\/article\/image-20240930232723219.png\" alt=\"image-20240930232723219\" \/><\/p>\n<p>\u7b49\u5f85\u68c0\u67e5\u5b8c\u6210<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/img.nozomicloud.top\/\/blog\/article\/image-20240930232821372.png\" alt=\"image-20240930232821372\" \/><\/p>\n<p>\u9009\u62e9\u4e4b\u524d\u6b65\u9aa4\u4e2d\u521b\u5efa\u7684d2l\u73af\u5883<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/img.nozomicloud.top\/\/blog\/article\/image-20240930234014534.png\" alt=\"image-20240930234014534\" \/><\/p>\n<p>\u5728python\u7ec8\u7aef\u4e2d\u6d4b\u8bd5\u53ef\u7528\u6027<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/img.nozomicloud.top\/\/blog\/article\/image-20240930234256684.png\" alt=\"image-20240930234256684\" \/><\/p>\n<blockquote>\n<p>\u672c\u6587\u5728\u5199\u4f5c\u8fc7\u7a0b\u4e2d\u53c2\u8003\u4e86\u4ee5\u4e0b\u8d44\u6599<\/p>\n<p><a href=\"https:\/\/zh.d2l.ai\/chapter_installation\/index.html\">https:\/\/zh.d2l.ai\/chapter_installation\/index.html<\/a><\/p>\n<p><a href=\"https:\/\/blog.yotroy.cool\/?p=274\">https:\/\/blog.yotroy.cool\/?p=274<\/a><\/p>\n<p><a href=\"https:\/\/www.jetbrains.com\/help\/pycharm\/using-wsl-as-a-remote-interpreter.html#wsl-terminal\">https:\/\/www.jetbrains.com\/help\/pycharm\/using-wsl-as-a-remote-interpreter.html#wsl-terminal<\/a><\/p>\n<\/blockquote>\n<hr \/>\n","protected":false},"excerpt":{"rendered":"<p>\u5e8f \u56fd\u5e86\u95f2\u6765\u65e0\u4e8b\uff0c\u51b3\u5b9a\u81ea\u5df1\u5b9e\u9645\u64cd\u4f5c\u4e00\u4e0b\u3002\u9996\u5148\u8981\u5b8c\u6210\u7684\u4efb\u52a1\u5c31\u662f\u73af\u5883\u642d\u5efa\u3002\u672c\u6559\u7a0b\u662fNvdia\u72ec\u663e+Windows\u7535 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":218,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[8,9,10,11,13,22],"class_list":["post-216","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-experience","tag-ai","tag-cuda","tag-pycharm","tag-pytorch","tag-wsl","tag-22"],"_links":{"self":[{"href":"https:\/\/blog.faspand.top\/index.php\/wp-json\/wp\/v2\/posts\/216","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.faspand.top\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.faspand.top\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.faspand.top\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.faspand.top\/index.php\/wp-json\/wp\/v2\/comments?post=216"}],"version-history":[{"count":0,"href":"https:\/\/blog.faspand.top\/index.php\/wp-json\/wp\/v2\/posts\/216\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.faspand.top\/index.php\/wp-json\/wp\/v2\/media\/218"}],"wp:attachment":[{"href":"https:\/\/blog.faspand.top\/index.php\/wp-json\/wp\/v2\/media?parent=216"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.faspand.top\/index.php\/wp-json\/wp\/v2\/categories?post=216"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.faspand.top\/index.php\/wp-json\/wp\/v2\/tags?post=216"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}