Need guidance on pytorch dependency size reduction inside docker image using nvidia-container-toolkit

mithun: <p>Dear All, Greetings.<br>
I need to containerise an AI/ML module which is prgrammed to use following:<br>
model: huggingface bge-v2-m3 reranker<br>
needed dependency: torch (pytorch)<br>
hardware: nvidia GPU<br>
format: container based deployment/runtime<br>
installed dependencies via pip: pytorch - which brings in all nvidia cuda packages</p>
<p>I am experienced with general containerization. But new to GPU, cuda, etc related ecosystem.<br>
In dockerfile, I am installing pytorch via pip - the default GPU cuda variant, and it is installing a lot of dependencies.<br>
Total size is around 4.4 GB.<br>
I need to run this image on a docker runtime having some GPU hardware.<br>
I have to learn how to assemble/setup the container runtime on the GPU machine.</p>
<p>I have spent some time reading about nvidia-container-toolkit.<br>
Please advise/guide me on following points:</p>
<ol>
<li>whether installing nvidia-container-toolkit on host will help reduce any of pip dependencies inside the container image?</li>
<li>whether I need to install cuda toolkit also on host? (cuda-toolkit)</li>
<li>do I need to install nvidia gpu driver/ GDS also on host? (nvidia-gds)</li>
<li>whether any of nvidia-container-toolkit or libnvidia-container1 or nvidia-container-tools contain any cuda related driver contents/ .so files to run pytorch?</li>
<li>mainly what is the difference between pytorch’s nvidia cuda pip dependencies and nvidia-container-runtime provided libraries?</li>
</ol>

ptrblck: <ol>
<li>No.</li>
<li>No, you would need to install an NVIDIA Driver and properly set up the container environment.</li>
<li>You need to install the NVIDIA Driver, but don’t need to install GDS.</li>
<li>These libs are needed to provide GPU support for your docker containers.</li>
<li>CUDA libraries hosted as pip wheels on PyPI provide the runtime library dependencies and PyTorch will use these to execute their kernels on the GPU. The container runtime is unrelated to PyTorch or any other CUDA application and allows you to use GPUs in docker containers.</li>
</ol>

mithun: <p>Thanks a lot <a class="mention" href="/u/ptrblck">@ptrblck</a> !<br>
I need one more info clarification regarding the setup of ‘nvidia container toolkit’. I am not sure if this would be the right forum to ask this. Kindly guide appropriate forum:</p>
<p>My production runtime is on a Linux machine which can install ‘rpm’ format files (RHEL or Azure Linux or Amazon Linux). That machine would have nvidia GPU [example: AWS EC2 - g4dn instances, having nvidia g4]. I would be installing ‘docker’ runtime on that, and configure it to run on GPU using nvidia container toolkit.<br>
On this docker, I intend to run an image containing huggingface model along with pytorch and its nvidia cuda dependencies inside that.</p>
<p>My query is about which all rpm packages need to be installed on the host and which all rpms should be installed inside the container?</p>
<p>I have gone through the following documentation:</p>
<p>Architecture Overview:<br>
<a href="https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/latest/arch-overview.html" class="onebox" target="_blank" rel="noopener nofollow ugc">https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/latest/arch-overview.html</a></p>
<p>Install guide:<br>
<a href="https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/latest/install-guide.html" class="onebox" target="_blank" rel="noopener nofollow ugc">https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/latest/install-guide.html</a></p>
<p>I am still not clear. I connected to nvidia rpm repo and downloaded all available rpm files. I see following:<br>
libnvidia-container1<br>
libnvidia-container-tools<br>
nvidia-container-runtime<br>
nvidia-container-toolkit<br>
nvidia-container-toolkit-base (I think this gets covered by nvidia-container-toolkit)<br>
nvidia-docker2</p>
<p>from the above list of rpms, which of these should be installed on host and which all inside container image?<br>
Kindly guide me.</p>

ptrblck: <p>I’m not familiar with AWS instances and would assume they are already configured to run CUDA applications. I set up nodes locally with docker by following <a href="https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/latest/install-guide.html">this guide</a>.</p>

mithun: <p>Hi <a class="mention" href="/u/ptrblck">@ptrblck</a> ,<br>
Thanks for your response. As per the installing guide documentation, it seems to be only 1 rpm file to be installed on host/server. Nothing to be installed inside the container image to connect with that. Kindly confirm my understanding.</p>