Skip to content

Instantly share code, notes, and snippets.

@Delshi
Last active November 28, 2025 22:07
Show Gist options
  • Select an option

  • Save Delshi/2299a31fb6a5302ac97c172e514db62e to your computer and use it in GitHub Desktop.

Select an option

Save Delshi/2299a31fb6a5302ac97c172e514db62e to your computer and use it in GitHub Desktop.
PyTorch Poetry Boilerplate — CUDA 12.8 & CPU-only (package-mode = false).

PyTorch Poetry Boilerplate (CUDA + CPU)

Ready-to-use pyproject.toml templates for PyTorch-based neural network projects, optimized for both local development and future PyPI distribution.


Files

  • pyproject-cuda128.toml — installs PyTorch with CUDA 12.8 support from the official PyTorch wheel index.
  • pyproject-cpu.toml — pure CPU-only version using standard PyPI wheels.

Both files are pre-configured with package-mode = false for local experimentation (no need to structure your code as a package).


Need to change CUDA version?

  • Define which version of CUDA your GPU supports. You can do it here: CUDA Compability Table
  • Make sure that CUDA installed on your PC. Guide: CUDA Quick Start | Windows | Linux
  • In pyproject-cuda128.toml change source url = "https://download.pytorch.org/whl/cu128" to your version. For example, for CUDA v. 12.7 the end of url will be cu127

Quick Start

  1. Choose your version:
    # For NVIDIA GPU (CUDA 12.8)
    cp pyproject-cuda128.toml pyproject.toml
    
    # OR for CPU-only
    cp pyproject-cpu.toml pyproject.toml
    
  2. Initialize Poetry environment:
poetry install
  1. Run poetry env activate

  2. Start coding! No src/ layout or package structure required


Want publish to PyPi Later?

  1. Set package-mode = true
  2. Uncomment this line:
# packages = [{ include = "your_package_name", from = "src" }]
  1. Move your code into src/your_package_name/
  2. Ensure your project has a valid __init__.py
  3. Run poetry build and poetry publish

Keep package-mode = false during research/prototyping. Switch to true only when preparing a distributable library


Included Dependencies

  • torch, torchaudio, torchvision (CUDA or CPU)
  • tensorboard
  • numpy, scikit-learn
  • matplotlib, seaborn
  • tqdm

Don't need some of included dependencies?

Just remove it:

poetry remove unnecessary-dependency-name

License

MIT — feel free to fork, modify, and use in your projects.

[project]
name = "your-beautiful-neural-network"
version = "0.1.0"
description = "A flexible PyTorch-based neural network boilerplate (CPU-only)"
authors = [{ name = "Your Name", email = "[email protected]" }]
readme = "README.md"
requires-python = ">=3.10,<3.15"
license = { text = "MIT" }
classifiers = [
"Development Status :: 3 - Alpha",
"Intended Audience :: Developers",
"Intended Audience :: Science/Research",
"License :: OSI Approved :: MIT License",
"Programming Language :: Python :: 3",
"Topic :: Scientific/Engineering :: Artificial Intelligence",
]
dependencies = [
"torch >=2.9.1,<3.0.0", # CPU wheel from PyPI
"torchaudio >=2.9.1,<3.0.0",
"torchvision >=0.24.1,<0.25.0",
"numpy >=2.0.0,<3.0.0",
"tensorboard >=2.20.0,<3.0.0",
"scikit-learn >=1.5.0,<2.0.0",
"tqdm >=4.66.0,<5.0.0",
"matplotlib (>=3.10.7,<4.0.0)",
"seaborn (>=0.13.2,<0.14.0)"
]
[tool.poetry]
package-mode = false
# package-mode = true
# packages = [{ include = "your_package_name", from = "src" }]
[tool.poetry.dependencies]
python = "^3.10"
torch = ">=2.9.1,<3.0.0"
torchaudio = ">=2.9.1,<3.0.0"
torchvision = ">=0.24.1,<0.25.0"
[build-system]
requires = ["poetry-core>=2.0.0,<3.0.0"]
build-backend = "poetry.core.masonry.api"
[project]
name = "your-beautiful-neural-network"
version = "0.1.0"
description = "A flexible PyTorch-based neural network boilerplate supporting CUDA 12.8"
authors = [{ name = "Your Name", email = "[email protected]" }]
readme = "README.md"
requires-python = ">=3.10,<3.15"
license = { text = "MIT" }
classifiers = [
"Development Status :: 3 - Alpha",
"Intended Audience :: Developers",
"Intended Audience :: Science/Research",
"License :: OSI Approved :: MIT License",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Topic :: Scientific/Engineering :: Artificial Intelligence",
]
dependencies = [
"torch >=2.9.1,<3.0.0",
"torchaudio >=2.9.1,<3.0.0",
"torchvision >=0.24.1,<0.25.0",
"numpy >=2.0.0,<3.0.0",
"tensorboard >=2.20.0,<3.0.0",
"scikit-learn >=1.5.0,<2.0.0",
"tqdm >=4.66.0,<5.0.0",
"matplotlib (>=3.10.7,<4.0.0)",
"seaborn (>=0.13.2,<0.14.0)"
]
[tool.poetry]
package-mode = false
# package-mode = true
# packages = [{ include = "your_package_name", from = "src" }]
[[tool.poetry.source]]
name = "torch-cu128"
url = "https://download.pytorch.org/whl/cu128"
priority = "explicit"
[tool.poetry.dependencies]
python = "^3.10"
torch = { version = ">=2.9.1,<3.0.0", source = "torch-cu128" }
torchaudio = { version = ">=2.9.1,<3.0.0", source = "torch-cu128" }
torchvision = { version = ">=0.24.1,<0.25.0", source = "torch-cu128" }
[build-system]
requires = ["poetry-core>=2.0.0,<3.0.0"]
build-backend = "poetry.core.masonry.api"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment