<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Tensorflow &#8211; richliu&#039;s blog</title>
	<atom:link href="https://richliu.com/tag/tensorflow/feed/" rel="self" type="application/rss+xml" />
	<link>https://richliu.com</link>
	<description>Linux, 工作, 生活, 家人</description>
	<lastBuildDate>Fri, 23 Jun 2023 09:01:04 +0000</lastBuildDate>
	<language>zh-TW</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>
	<item>
		<title>Run Keras or TensorFlow in WSL2 with Nvidia GPU</title>
		<link>https://richliu.com/2023/06/23/5238/run-keras-or-tensorflow-in-wsl2-with-nvidia-gpu/</link>
					<comments>https://richliu.com/2023/06/23/5238/run-keras-or-tensorflow-in-wsl2-with-nvidia-gpu/#respond</comments>
		
		<dc:creator><![CDATA[richliu]]></dc:creator>
		<pubDate>Fri, 23 Jun 2023 07:17:00 +0000</pubDate>
				<category><![CDATA[AI]]></category>
		<category><![CDATA[CUDA]]></category>
		<category><![CDATA[gpu]]></category>
		<category><![CDATA[Keras]]></category>
		<category><![CDATA[Nvidia]]></category>
		<category><![CDATA[Tensorflow]]></category>
		<category><![CDATA[WSL2]]></category>
		<guid isPermaLink="false">https://richliu.com/?p=5238</guid>

					<description><![CDATA[<p>When this article is finished, it will still be unable  [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://richliu.com/2023/06/23/5238/run-keras-or-tensorflow-in-wsl2-with-nvidia-gpu/">Run Keras or TensorFlow in WSL2 with Nvidia GPU</a> appeared first on <a rel="nofollow" href="https://richliu.com">richliu&#039;s blog</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>When this article is finished, it will still be unable to run Keras or TensorFlow within Conda or a virtual environment. This is because TensorFlow/Keras will display an error message similar to the one below (cut):</p>



<pre class="wp-block-preformatted">Node: 'model_3/conv1d_24/Conv1D' 
DNN library is not found. 	 [[{{node model_3/conv1d_24/Conv1D}}]] [Op:__inference_train_function_34509]</pre>



<p>It seems that there may be compatibility issues between the versions of TensorFlow/Keras installed outside of Conda and those installed within Conda. But it maybe also cause by tensorflow 2.12 has issue, please re-install 2.10 and try again . <br />Specified version can work well cuDNN 8.9, CUDA 11.8 and TensorFlow 2.10. <br />Here is how to re-install tensorflow 2.10 instruction.<br /></p>



<span id="more-5238"></span>



<pre class="wp-block-preformatted">pip uninstall tensorflow
pip install tensorflow-gpu
pip install tensorflow-gpu==2.10 </pre>



<p><br />ref. <br /><a href="https://github.com/tensorflow/tensorflow/issues/60101" target="_blank" rel="noreferrer noopener">TensorFlow 2.12.0 WSL2 GPU support</a></p>



<p>Have tried someother way, all of them doesn&#8217;t work when you use 2.12 tensorflow. Don&#8217;t try this. ex:</p>



<pre class="wp-block-preformatted">sudo cp cuda/include/cudnn*.h   /anaconda3/envs/&lt;your environment here&gt;/include
sudo cp cuda/lib64/libcudnn*    /anaconda3/envs/&lt;your environment here&gt;/lib
sudo chmod a+r /usr/local/cuda/include/cudnn*.h    /anaconda3/envs/&lt;your environment here&gt;/lib/libcudnn*</pre>



<p>ref.<br /><a href="https://stackoverflow.com/questions/55256671/how-to-install-latest-cudnn-to-conda" target="_blank" rel="noreferrer noopener">How to install latest cuDNN to conda?</a></p>



<h2 class="wp-block-heading">Install</h2>



<h3 class="wp-block-heading">CUDA</h3>



<p>Suppose it already install WSL2 on your system, please follow the <a href="https://docs.nvidia.com/cuda/wsl-user-guide/index.html" target="_blank" rel="noreferrer noopener">CUDA on WSL User Guide</a> to install WSL, for Tensorflow 2.12, suggestion CUDA version is 11.8. <a href="https://developer.nvidia.com/cuda-11-8-0-download-archive?target_os=Linux&amp;target_arch=x86_64&amp;Distribution=WSL-Ubuntu&amp;target_version=2.0&amp;target_type=deb_local" target="_blank" rel="noreferrer noopener">Can be found here CUDA Toolkit 11.8 Downloads</a></p>



<pre class="wp-block-preformatted">wget https://developer.download.nvidia.com/compute/cuda/repos/wsl-ubuntu/x86_64/cuda-wsl-ubuntu.pin
sudo mv cuda-wsl-ubuntu.pin /etc/apt/preferences.d/cuda-repository-pin-600
wget https://developer.download.nvidia.com/compute/cuda/11.8.0/local_installers/cuda-repo-wsl-ubuntu-11-8-local_11.8.0-1_amd64.deb
sudo dpkg -i cuda-repo-wsl-ubuntu-11-8-local_11.8.0-1_amd64.deb
sudo cp /var/cuda-repo-wsl-ubuntu-11-8-local/cuda-*-keyring.gpg /usr/share/keyrings/
sudo apt-get update
sudo apt-get -y install cuda</pre>



<h3 class="wp-block-heading">cuDNN</h3>



<p>It still needs to install CUDNN, follow this instruction to download CUDNN 8.9.x, <a href="https://docs.nvidia.com/deeplearning/cudnn/install-guide/index.html#install-linux" target="_blank" rel="noopener">Installing cuDNN on Linux</a>. Download cuDNN needs to register Nvidia account. <br />Download address : <a href="https://developer.nvidia.com/rdp/cudnn-download" target="_blank" rel="noreferrer noopener">cuDNN Download</a>, it has cuDNN for CUDA 12 and CUDA 11, download for CUDA 11. </p>



<h3 class="wp-block-heading">Add Path to System Path</h3>



<p>Put following seting into ~/.bashrc, thus it can update when get bash console </p>



<pre class="wp-block-preformatted">export PATH=/usr/local/cuda/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH</pre>



<h3 class="wp-block-heading">Follow tensorflow install guide to install tensorflow.</h3>



<p><a href="https://www.tensorflow.org/install/pip#windows-wsl2_1" target="_blank" rel="noreferrer noopener">Tensorflow step by step instructions for WSL2</a></p>



<h2 class="wp-block-heading">Python Virtual Environment</h2>



<p>if use virtual venv, it also can work, just need to install right version tensorflow. and it needs to configure cuDNN path on activate script </p>



<pre class="wp-block-preformatted">vim &lt;path to venv&gt;/bin/activate

# After get VIRTUAL_ENV, include the CUDNN path
export VIRTUAL_ENV

CUDNN_PATH=$(dirname $(python -c "import nvidia.cudnn;print(nvidia.cudnn.__file__)"))
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$VIRTUAL_ENV/lib/:$CUDNN_PATH/lib
</pre>



<h2 class="wp-block-heading">Reference</h2>



<p><a href="https://hackmd.io/@Kailyn/HkSTXL9xK" target="_blank" rel="noreferrer noopener">WSL2 安裝 CUDA Toolkit、cuDNN</a></p>



<p><br /></p>
<p>The post <a rel="nofollow" href="https://richliu.com/2023/06/23/5238/run-keras-or-tensorflow-in-wsl2-with-nvidia-gpu/">Run Keras or TensorFlow in WSL2 with Nvidia GPU</a> appeared first on <a rel="nofollow" href="https://richliu.com">richliu&#039;s blog</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://richliu.com/2023/06/23/5238/run-keras-or-tensorflow-in-wsl2-with-nvidia-gpu/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
