This template currently uses
Python 3.11,Python 3.12, and eitherconda,poetry, orcondaormicromamba
Template project aims to promote versioning library, environment isolation practice and help all ML practitioners quickly start a project. Using this template, practitioners will have below libraries
- Pytorch
- Torch-geometric
- Transfomer
- Pytorch-Lightning
- Wandb
- Pandas
- Numpy
- Scikit-Learn
- Jupyter Notebook
- Panel
- Pytest
- DVC
Those libraries of course aren't enough, but it's easy to update other libraries that support your project.
Using
poetryis highly recommended. If you are usingcondaormicromamba, make sure that you use package hashes to ensure package selection is reproducible viaconda-lock.
- This tutorial is for those who have NVIDIA GPU (hereafter GPU), and you must have
docker. Note that, this approach will include your private ssh key to built image. DO NOT push built image without changing Dockerfile. - Install Nvidia driver
- Then install Nvidia docker container toolkit.
docker run -v "$PWD:/workspace" --gpus all --rm -it pytorch/pytorch:2.4.1-cuda12.4-cudnn9-runtime bashpoetry installpoetry shell
- Note: Docker will use
micromambainstead ofminiconda. Replacecondawithmicromambain your usual commands - Edit
.envlocates the same level withrun_docker.sh, to add environment variables to the prospective docker container - There is a file named
run_docker.sh, allow to execute it bychmod +x run_docker.shand runrun_docker.sh - Enjoy Jupyter lab at localhost:8888 as usual. Notebook token is shown after
run_docker.shruns successfully
pip install poetry- Create, install, activate environment
poetry install
poetry shell- Need to update environment after
poetry add a_lib
poetry lockNote: in case you have a problem, run
export PYTHON_KEYRING_BACKEND=keyring.backends.null.Keyring- Need to add source, e.g
pyg-cu117
poetry source add pyg-cu117 https://data.pyg.org/whl/torch-2.0.0+cu117.htmlsupposing add pyg_lib, torch_scatter, ... to a group (cu117) in this project via the source
poetry add -G cu117 pyg_lib torch_scatter torch_sparse torch_cluster torch_spline_conv --source pyg-cu117- Install Conda instruction: conda.io
- Create, install, activate environment
conda env create -f environment.yml
conda activate ml-venv- Need to update environment
conda env update --file binder/environment.yml --prune- Export environment
conda env export --from-history -f binder/environment.ymltry this in ipython
import torch
from torch_geometric.data import Data
from transformers import pipeline
print(torch.cuda.is_available())
edge_index = torch.tensor([[0, 1],
[1, 0],
[1, 2],
[2, 1]], dtype=torch.long)
x = torch.tensor([[-1], [0], [1]], dtype=torch.float)
data = Data(x=x, edge_index=edge_index.t().contiguous())
print(data)
classifier = pipeline("sentiment-analysis")
result = classifier("We are very happy to show you the 🤗 Transformers library.")
print(result)