{"id":19601638,"url":"https://github.com/alankrantas/tensorflow-cuda-gpu-devcontainer","last_synced_at":"2025-04-27T17:32:02.449Z","repository":{"id":188527679,"uuid":"678918253","full_name":"alankrantas/tensorflow-cuda-gpu-devcontainer","owner":"alankrantas","description":"Tensorflow CUDA DevContainer Configuration for Supporting NVIDIA GPU","archived":false,"fork":false,"pushed_at":"2024-05-01T07:00:53.000Z","size":76,"stargazers_count":7,"open_issues_count":0,"forks_count":2,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-05-02T10:19:50.471Z","etag":null,"topics":["cuda","cudnn","deep-learning","devcontainer","gpu-acceleration","keras","machine-learning","nvidia","nvidia-gpu","tensorflow"],"latest_commit_sha":null,"homepage":"","language":"Jupyter Notebook","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/alankrantas.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-08-15T17:25:53.000Z","updated_at":"2024-05-01T07:01:24.000Z","dependencies_parsed_at":"2024-05-01T04:32:06.670Z","dependency_job_id":"2144ac93-124a-4a2d-a2aa-ab29d13fb3e3","html_url":"https://github.com/alankrantas/tensorflow-cuda-gpu-devcontainer","commit_stats":{"total_commits":19,"total_committers":1,"mean_commits":19.0,"dds":0.0,"last_synced_commit":"830253a49cb28381e0683e2a5ae962b0d356326d"},"previous_names":["alankrantas/windows-cuda-gpu-devcontainer","alankrantas/python-cuda-devcontainer-windows-gpu","alankrantas/cuda-cudnn-gpu-devcontainer","alankrantas/tensorflow-cuda-gpu-devcontainer"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alankrantas%2Ftensorflow-cuda-gpu-devcontainer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alankrantas%2Ftensorflow-cuda-gpu-devcontainer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alankrantas%2Ftensorflow-cuda-gpu-devcontainer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alankrantas%2Ftensorflow-cuda-gpu-devcontainer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alankrantas","download_url":"https://codeload.github.com/alankrantas/tensorflow-cuda-gpu-devcontainer/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224076424,"owners_count":17251752,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cuda","cudnn","deep-learning","devcontainer","gpu-acceleration","keras","machine-learning","nvidia","nvidia-gpu","tensorflow"],"created_at":"2024-11-11T09:19:17.455Z","updated_at":"2024-11-11T09:19:18.603Z","avatar_url":"https://github.com/alankrantas.png","language":"Jupyter Notebook","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Tensorflow CUDA DevContainer Configuration for Supporting NVIDIA GPU\n\nTo create a Docker Linux DevContainer that supports Tensorflow GPU without frustrating and complicated local installation, especially on Windows platforms.\n\nThe current version willl create the following setup:\n\n* Python `3.11`\n* Tensorflow `2.15.0`\n* CUDA `12.2` + cuDNN\n\n\u003e The current version utilizes `tensorflow[and-cuda]` to install compatible CUDA/cuDNN on a regular Python container. My original and previous version used a NVIDIA CUDA image to install Python and cuDNN.\n\u003e \n\u003e For now Tensorflow `2.16.1` cannot be installed currectly. And, I still have no success to have installed TensorRT detected. Let me know if you managed to get it running!\n\nThe current version has been tested on:\n\n* A Windows 11 gaming laptop with a built-in RTX 3070 Ti\n\n\u003e I've tried with my another laptop connecting to a eGPU (GTX 1660 Ti) without success so far.\n\n## Prerequisites\n\n* An amd64 (x64) machine with a CUDA-compatible NVIDIA GPU card\n* [Docker engine](https://docs.docker.com/engine/install/) or [Docker Desktop](https://docs.docker.com/desktop/install/windows-install/) (and setup [.wslconfig](https://learn.microsoft.com/en-us/windows/wsl/wsl-config) to use more cores and memory than default if you are on Windows.)\n* Latest version of the [NVIDIA graphic card driver](https://www.nvidia.com/download/index.aspx)\n* [NVIDIA Container Toolkit](https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/latest/install-guide.html) (which is already included in Windows’ Docker Desktop)\n* [Visual Studio Code](https://code.visualstudio.com/download) with [DevContainer extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers) installed\n\nSee [here](https://www.tensorflow.org/install/pip#hardware_requirements) for more detailed hardware and system requirements of running Tensorflow.\n\n\u003e Note: some deep learning models require more GPU memory than others and may cause the Python kernel to crash. You may need to try setting a smaller training batch size.\n\u003e\n\u003e Some older cards may only support older drivers thus older CUDA versions. See the CUDA [Support Matrix](https://docs.nvidia.com/deeplearning/cudnn/latest/reference/support-matrix.html) for details, although I cannot test if `tensorflow[and-cuda]` will install older libraries automatically.\n\n## Download Repo\n\nDownload the repo as a .zip file, unzip then open the folder in VS Code, or to use [Git](https://git-scm.com/):\n\n```bash\ngit clone https://github.com/alankrantas/tensorflow-cuda-gpu-devcontainer.git\ncd tensorflow-cuda-gpu-devcontainer\ncode .\n```\n\nModify [requirements.txt](https://github.com/alankrantas/windows-cuda-gpu-devcontainer/blob/main/.devcontainer/requirements.txt) to include packages you'd like to install. `ipykernel` is required for executing IPython notebook cells in VS Code.\n\n\u003e Note: VS Code/Git may messed up the new line characters of `.devcontainer/install-dev-tools.sh` and `.devcontainer/requirements` which will cause the DevContainer failed to run the scripts.\n\u003e\n\u003e Click `CRLF` on the button right and change them to `LF`.\n\n## Start DevContainer\n\nIn VS Code, press `F1` to bring up the Command Palette, and select **Dev Containers: Open Folder in Container...**\n\nWait until the DevContainer is up and running (`nvidia-smi` is executed):\n\n```\nWed May  1 03:24:54 2024       \n+-----------------------------------------------------------------------------------------+\n| NVIDIA-SMI 550.76.01              Driver Version: 552.22         CUDA Version: 12.4     |\n|-----------------------------------------+------------------------+----------------------+\n| GPU  Name                 Persistence-M | Bus-Id          Disp.A | Volatile Uncorr. ECC |\n| Fan  Temp   Perf          Pwr:Usage/Cap |           Memory-Usage | GPU-Util  Compute M. |\n|                                         |                        |               MIG M. |\n|=========================================+========================+======================|\n|   0  NVIDIA GeForce RTX 3070 ...    On  |   00000000:01:00.0 Off |                  N/A |\n| N/A   46C    P0             29W /  130W |       0MiB /   8192MiB |      0%      Default |\n|                                         |                        |                  N/A |\n+-----------------------------------------+------------------------+----------------------+\n                                                                                         \n+-----------------------------------------------------------------------------------------+\n| Processes:                                                                              |\n|  GPU   GI   CI        PID   Type   Process name                              GPU Memory |\n|        ID   ID                                                               Usage      |\n|=========================================================================================|\n|  No running processes found                                                             |\n+-----------------------------------------------------------------------------------------+\n```\n\n\u003e Although `nvidia-smi` informed us the current NVIDIA driver uses CUDA `12.4`, it doesn't mean Tensorflow supports it. This is why using `tensorflow[and-cuda]` is easier to use existing NVIDIA CUDA/cuDNN images.\n\nThen open a new terminal (`Terminal` -\u003e `New Terminal`) to test if the Tensorflow detects the GPU correctly:\n\n```python\npython3 -c \"import tensorflow as tf; print(tf.config.list_physical_devices('GPU'))\"\n```\n\nIf success, you should see something like\n\n```\n[PhysicalDevice(name='/physical_device:GPU:0', device_type='GPU')]\n```\n\nAfterwards, simply open the folder in VS Code to restart the built container.\n\n## Test Script\n\nTest run using the example file - open `autokeras-test.py` and seletct `Run` -\u003e `Run Without Debugging`, or run in the terminal\n\n```python\npython3 autokeras-test.py\n```\n\nWhich generates a result like below:\n\n```\nTrial 1 Complete [00h 03m 51s]\nval_loss: 0.03894084319472313\n\nBest val_loss So Far: 0.03894084319472313\nTotal elapsed time: 00h 03m 51s\n\n...\n\nPrediction loss: 0.0315\nPrediction accuracy: 0.9910\n              precision    recall  f1-score   support\n\n           0       0.99      1.00      0.99       980\n           1       1.00      1.00      1.00      1135\n           2       0.99      0.99      0.99      1032\n           3       0.99      1.00      0.99      1010\n           4       0.99      0.99      0.99       982\n           5       0.99      0.99      0.99       892\n           6       1.00      0.98      0.99       958\n           7       0.99      0.99      0.99      1028\n           8       0.99      0.99      0.99       974\n           9       0.99      0.99      0.99      1009\n\n    accuracy                           0.99     10000\n   macro avg       0.99      0.99      0.99     10000\nweighted avg       0.99      0.99      0.99     10000\n```\n\nOr open `autokeras-test.ipynb`, run the cells or select `Run All` on top of the notebook.\n\n## Resources\n\n* [Developing inside a Container](https://code.visualstudio.com/docs/devcontainers/containers)\n* [Install TensorFlow with pip](https://www.tensorflow.org/install/pip)\n* [Setup a NVIDIA DevContainer with GPU Support for Tensorflow/Keras on Windows](https://alankrantas.medium.com/setup-a-nvidia-devcontainer-with-gpu-support-for-tensorflow-keras-on-windows-d00e6e204630)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falankrantas%2Ftensorflow-cuda-gpu-devcontainer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falankrantas%2Ftensorflow-cuda-gpu-devcontainer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falankrantas%2Ftensorflow-cuda-gpu-devcontainer/lists"}