{"id":17226622,"url":"https://github.com/clee-ai/3d-ml","last_synced_at":"2025-04-14T01:12:52.092Z","repository":{"id":63427828,"uuid":"564399817","full_name":"clee-ai/3d-ml","owner":"clee-ai","description":"A versatile framework for 3D machine learning built on Pytorch Lightning and Hydra [looking for contributors!]","archived":false,"fork":false,"pushed_at":"2025-03-31T18:42:08.000Z","size":112,"stargazers_count":16,"open_issues_count":24,"forks_count":3,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-04-14T01:12:40.989Z","etag":null,"topics":["3d","3d-deep-learning","deep-learning","point-cloud","pytorch","s3dis","segmentation"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/clee-ai.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2022-11-10T16:27:12.000Z","updated_at":"2025-04-09T10:23:07.000Z","dependencies_parsed_at":"2023-12-25T20:56:16.543Z","dependency_job_id":"fbc6dc26-69aa-458d-b145-f6fa44b24ef9","html_url":"https://github.com/clee-ai/3d-ml","commit_stats":null,"previous_names":["clee-ai/3d-ml","ccinc/3d-ml"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clee-ai%2F3d-ml","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clee-ai%2F3d-ml/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clee-ai%2F3d-ml/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clee-ai%2F3d-ml/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/clee-ai","download_url":"https://codeload.github.com/clee-ai/3d-ml/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248804825,"owners_count":21164135,"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":["3d","3d-deep-learning","deep-learning","point-cloud","pytorch","s3dis","segmentation"],"created_at":"2024-10-15T04:16:47.656Z","updated_at":"2025-04-14T01:12:52.047Z","avatar_url":"https://github.com/clee-ai.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n\n# 3D-ML\n\n\u003ca href=\"https://pytorch.org/get-started/locally/\"\u003e\u003cimg alt=\"PyTorch\" src=\"https://img.shields.io/badge/PyTorch-ee4c2c?logo=pytorch\u0026logoColor=white\"\u003e\u003c/a\u003e\n\u003ca href=\"https://pytorchlightning.ai/\"\u003e\u003cimg alt=\"Lightning\" src=\"https://img.shields.io/badge/-Lightning-792ee5?logo=pytorchlightning\u0026logoColor=white\"\u003e\u003c/a\u003e\n\u003ca href=\"https://hydra.cc/\"\u003e\u003cimg alt=\"Config: Hydra\" src=\"https://img.shields.io/badge/Config-Hydra-89b8cd\"\u003e\u003c/a\u003e\n\u003ca href=\"https://github.com/ashleve/lightning-hydra-template\"\u003e\u003cimg alt=\"Template\" src=\"https://img.shields.io/badge/-Lightning--Hydra--Template-017F2F?style=flat\u0026logo=github\u0026labelColor=gray\"\u003e\u003c/a\u003e\u003cbr\u003e\n\n\u003c/div\u003e\n\n**A versatile framework for 3D machine learning built on Pytorch Lightning and Hydra.**\n\nPlease see the [Project Guidelines](#project-guidelines) section before diving into the code!\n\n## 💻 Conda Installation (recommended)\n\n```bash\n# clone project\ngit clone https://github.com/CCInc/3d-ml.git --recurse-submodules \u0026\u0026 cd 3d-ml\n\n\n# Create a fresh conda environment\nconda activate base\nconda create -n 3dml -y python=3.9\nconda activate 3dml\n\n# For GPU support see https://docs.nvidia.com/cuda/cuda-installation-guide-linux/index.html for CUDA toolkit installation instructions\nnvcc --version # To make sure you have the CUDA toolkit installed. Your PyTorch CUDA version must match your nvcc version.\n\n# Install pytorch\n# Pick a compatible combination of pytorch and cuda version from https://pytorch.org/\n# Below is an example for CUDA 11.3\nconda install pytorch==1.12.1 torchvision==0.13.1 cudatoolkit=11.3 -c pytorch -y\n\n# Install pyg\nconda install pyg pytorch-scatter -c pyg -y\n\n# install other requirements\npip install -r requirements.txt\n\n# install openpoints\n./install_openpoints.sh\n```\n\n## 💻 Pip Installation\n\n```bash\n# clone project with submodules\ngit clone https://github.com/CCInc/3d-ml.git --recurse-submodules \u0026\u0026 cd 3d-ml\n\n# (optional) create virtual environment with virtualenv\npython -m virtualenv env_3d\nsource env_3d/bin/activate\n\n# Install pytorch\n# Pick a compatible combination of pytorch and cuda version from https://pytorch.org/\n# Below is an example for CUDA 11.6\npip install torch torchvision --extra-index-url https://download.pytorch.org/whl/cu116\n\n# Install pytorch geo with pip\n# Below is an example for CUDA 11.6 and torch 1.13\npip install pyg-lib torch-scatter torch-sparse -f https://data.pyg.org/whl/torch-1.13.0+cu116.html\npip install torch-geometric\n\n# Install additional requirements\npip install -r requirements.txt\n\n# If using virtual environments remove the \"--user\" argument for the last two setup.py commands\n# in the file install_openpoints.sh.\n./install_openpoints.sh\n```\n\n## 🚀 Quickstart\n\nTrain with specific model, and dataset\n\n```bash\npython src/train.py model=cls_pointnet++ data=cls_modelnet2048\n```\n\nTrain model with chosen experiment configuration from [configs/experiment/](configs/experiment/)\n\n```bash\npython src/train.py experiment=cls_modelnet_pointnet++\n```\n\n## ⚡ Your Superpowers\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cb\u003eOverride any config parameter from command line\u003c/b\u003e\u003c/summary\u003e\n\n```bash\npython train.py trainer.max_epochs=20 model.optimizer.lr=1e-4\n```\n\n\u003e **Note**: You can also add new parameters with `+` sign.\n\n```bash\npython train.py +model.new_param=\"owo\"\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cb\u003eTrain on CPU, GPU, multi-GPU and TPU\u003c/b\u003e\u003c/summary\u003e\n\n```bash\n# train on CPU\npython train.py trainer=cpu\n\n# train on 1 GPU\npython train.py trainer=gpu\n\n# train on TPU\npython train.py +trainer.tpu_cores=8\n\n# train with DDP (Distributed Data Parallel) (4 GPUs)\npython train.py trainer=ddp trainer.devices=4\n\n# train with DDP (Distributed Data Parallel) (8 GPUs, 2 nodes)\npython train.py trainer=ddp trainer.devices=4 trainer.num_nodes=2\n\n# simulate DDP on CPU processes\npython train.py trainer=ddp_sim trainer.devices=2\n\n# accelerate training on mac\npython train.py trainer=mps\n```\n\n\u003e **Warning**: Currently there are problems with DDP mode, read [this issue](https://github.com/ashleve/lightning-hydra-template/issues/393) to learn more.\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cb\u003eTrain with mixed precision\u003c/b\u003e\u003c/summary\u003e\n\n```bash\n# train with pytorch native automatic mixed precision (AMP)\npython train.py trainer=gpu +trainer.precision=16\n```\n\n\u003c/details\u003e\n\n\u003c!-- deepspeed support still in beta\n\u003cdetails\u003e\n\u003csummary\u003e\u003cb\u003eOptimize large scale models on multiple GPUs with Deepspeed\u003c/b\u003e\u003c/summary\u003e\n\n```bash\npython train.py +trainer.\n```\n\n\u003c/details\u003e\n --\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cb\u003eTrain model with any logger available in PyTorch Lightning, like W\u0026B or Tensorboard\u003c/b\u003e\u003c/summary\u003e\n\n```yaml\n# set project and entity names in `configs/logger/wandb`\nwandb:\n  project: \"your_project_name\"\n  entity: \"your_wandb_team_name\"\n```\n\n```bash\n# train model with Weights\u0026Biases (link to wandb dashboard should appear in the terminal)\npython train.py logger=wandb\n```\n\n\u003e **Note**: Lightning provides convenient integrations with most popular logging frameworks. Learn more [here](#experiment-tracking).\n\n\u003e **Note**: Using wandb requires you to [setup account](https://www.wandb.com/) first. After that just complete the config as below.\n\n\u003e **Note**: Click [here](https://wandb.ai/hobglob/template-dashboard/) to see example wandb dashboard generated with this template.\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cb\u003eTrain model with chosen experiment config\u003c/b\u003e\u003c/summary\u003e\n\n```bash\npython train.py experiment=example\n```\n\n\u003e **Note**: Experiment configs are placed in [configs/experiment/](configs/experiment/).\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cb\u003eAttach some callbacks to run\u003c/b\u003e\u003c/summary\u003e\n\n```bash\npython train.py callbacks=default\n```\n\n\u003e **Note**: Callbacks can be used for things such as as model checkpointing, early stopping and [many more](https://pytorch-lightning.readthedocs.io/en/latest/extensions/callbacks.html#built-in-callbacks).\n\n\u003e **Note**: Callbacks configs are placed in [configs/callbacks/](configs/callbacks/).\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cb\u003eUse different tricks available in Pytorch Lightning\u003c/b\u003e\u003c/summary\u003e\n\n```yaml\n# gradient clipping may be enabled to avoid exploding gradients\npython train.py +trainer.gradient_clip_val=0.5\n\n# run validation loop 4 times during a training epoch\npython train.py +trainer.val_check_interval=0.25\n\n# accumulate gradients\npython train.py +trainer.accumulate_grad_batches=10\n\n# terminate training after 12 hours\npython train.py +trainer.max_time=\"00:12:00:00\"\n```\n\n\u003e **Note**: PyTorch Lightning provides about [40+ useful trainer flags](https://pytorch-lightning.readthedocs.io/en/latest/common/trainer.html#trainer-flags).\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cb\u003eEasily debug\u003c/b\u003e\u003c/summary\u003e\n\n```bash\n# runs 1 epoch in default debugging mode\n# changes logging directory to `logs/debugs/...`\n# sets level of all command line loggers to 'DEBUG'\n# enforces debug-friendly configuration\npython train.py debug=default\n\n# run 1 train, val and test loop, using only 1 batch\npython train.py debug=fdr\n\n# print execution time profiling\npython train.py debug=profiler\n\n# try overfitting to 1 batch\npython train.py debug=overfit\n\n# raise exception if there are any numerical anomalies in tensors, like NaN or +/-inf\npython train.py +trainer.detect_anomaly=true\n\n# log second gradient norm of the model\npython train.py +trainer.track_grad_norm=2\n\n# use only 20% of the data\npython train.py +trainer.limit_train_batches=0.2 \\\n+trainer.limit_val_batches=0.2 +trainer.limit_test_batches=0.2\n```\n\n\u003e **Note**: Visit [configs/debug/](configs/debug/) for different debugging configs.\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cb\u003eResume training from checkpoint\u003c/b\u003e\u003c/summary\u003e\n\n```yaml\npython train.py ckpt_path=\"/path/to/ckpt/name.ckpt\"\n```\n\n\u003e **Note**: Checkpoint can be either path or URL.\n\n\u003e **Note**: Currently loading ckpt doesn't resume logger experiment, but it will be supported in future Lightning release.\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cb\u003eEvaluate checkpoint on test dataset\u003c/b\u003e\u003c/summary\u003e\n\n```yaml\npython eval.py ckpt_path=\"/path/to/ckpt/name.ckpt\"\n```\n\n\u003e **Note**: Checkpoint can be either path or URL.\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cb\u003eCreate a sweep over hyperparameters\u003c/b\u003e\u003c/summary\u003e\n\n```bash\n# this will run 6 experiments one after the other,\n# each with different combination of batch_size and learning rate\npython train.py -m datamodule.batch_size=32,64,128 model.lr=0.001,0.0005\n```\n\n\u003e **Note**: Hydra composes configs lazily at job launch time. If you change code or configs after launching a job/sweep, the final composed configs might be impacted.\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cb\u003eCreate a sweep over hyperparameters with Optuna\u003c/b\u003e\u003c/summary\u003e\n\n```bash\n# this will run hyperparameter search defined in `configs/hparams_search/mnist_optuna.yaml`\n# over chosen experiment config\npython train.py -m hparams_search=mnist_optuna experiment=example\n```\n\n\u003e **Note**: Using [Optuna Sweeper](https://hydra.cc/docs/next/plugins/optuna_sweeper) doesn't require you to add any boilerplate to your code, everything is defined in a [single config file](configs/hparams_search/mnist_optuna.yaml).\n\n\u003e **Warning**: Optuna sweeps are not failure-resistant (if one job crashes then the whole sweep crashes).\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cb\u003eExecute all experiments from folder\u003c/b\u003e\u003c/summary\u003e\n\n```bash\npython train.py -m 'experiment=glob(*)'\n```\n\n\u003e **Note**: Hydra provides special syntax for controlling behavior of multiruns. Learn more [here](https://hydra.cc/docs/next/tutorials/basic/running_your_app/multi-run). The command above executes all experiments from [configs/experiment/](configs/experiment/).\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cb\u003eExecute run for multiple different seeds\u003c/b\u003e\u003c/summary\u003e\n\n```bash\npython train.py -m seed=1,2,3,4,5 trainer.deterministic=True logger=csv tags=[\"benchmark\"]\n```\n\n\u003e **Note**: `trainer.deterministic=True` makes pytorch more deterministic but impacts the performance.\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cb\u003eExecute sweep on a remote AWS cluster\u003c/b\u003e\u003c/summary\u003e\n\n\u003e **Note**: This should be achievable with simple config using [Ray AWS launcher for Hydra](https://hydra.cc/docs/next/plugins/ray_launcher). Example is not implemented in this template.\n\n\u003c/details\u003e\n\n\u003c!-- \u003cdetails\u003e\n\u003csummary\u003e\u003cb\u003eExecute sweep on a SLURM cluster\u003c/b\u003e\u003c/summary\u003e\n\n\u003e This should be achievable with either [the right lightning trainer flags](https://pytorch-lightning.readthedocs.io/en/latest/clouds/cluster.html?highlight=SLURM#slurm-managed-cluster) or simple config using [Submitit launcher for Hydra](https://hydra.cc/docs/plugins/submitit_launcher). Example is not yet implemented in this template.\n\n\u003c/details\u003e --\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cb\u003eUse Hydra tab completion\u003c/b\u003e\u003c/summary\u003e\n\n\u003e **Note**: Hydra allows you to autocomplete config argument overrides in shell as you write them, by pressing `tab` key. Read the [docs](https://hydra.cc/docs/tutorials/basic/running_your_app/tab_completion).\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cb\u003eApply pre-commit hooks\u003c/b\u003e\u003c/summary\u003e\n\n```bash\npre-commit run -a\n```\n\n\u003e **Note**: Apply pre-commit hooks to do things like auto-formatting code and configs, performing code analysis or removing output from jupyter notebooks. See [# Best Practices](#best-practices) for more.\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cb\u003eRun tests\u003c/b\u003e\u003c/summary\u003e\n\n```bash\n# run all tests\npytest\n\n# run tests from specific file\npytest tests/test_train.py\n\n# run all tests except the ones marked as slow\npytest -k \"not slow\"\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cb\u003eUse tags\u003c/b\u003e\u003c/summary\u003e\n\nEach experiment should be tagged in order to easily filter them across files or in logger UI:\n\n```bash\npython train.py tags=[\"mnist\", \"experiment_X\"]\n```\n\nIf no tags are provided, you will be asked to input them from command line:\n\n```bash\n\u003e\u003e\u003e python train.py tags=[]\n[2022-07-11 15:40:09,358][src.utils.utils][INFO] - Enforcing tags! \u003ccfg.extras.enforce_tags=True\u003e\n[2022-07-11 15:40:09,359][src.utils.rich_utils][WARNING] - No tags provided in config. Prompting user to input tags...\nEnter a list of comma separated tags (dev):\n```\n\nIf no tags are provided for multirun, an error will be raised:\n\n```bash\n\u003e\u003e\u003e python train.py -m +x=1,2,3 tags=[]\nValueError: Specify tags before launching a multirun!\n```\n\n\u003e **Note**: Appending lists from command line is currently not supported in hydra :(\n\n\u003c/details\u003e\n\n\u003cbr\u003e\n\n## Project Guidelines\n\nThis project is based on a plugin architecture and is to remain as lightweight as possible, serving merely as a connector between different downstream libraries. The main functions this framework is to serve is as follows:\n\n- Provide experiment configuration control with Hydra config\n- Provide consistent data augmentation and preprocessing steps across multiple datasets and models\n- Provide reference implementations of commonly used 3D datasets using PyL\n- Provide experiment tracking across a wide array of tools, e.g. Wandb and Tensorboard\n- Provide PyL wrappers for downstream libraries which provide model implementations and backends\n\n### Configuration\n\nRefer to the [Hydra docs](https://hydra.cc/docs/tutorials/intro/) for overall best practices when using Hydra configs.\n\nRelevant configuration parameters should be provided for every model/dataset to ensure easy reproducibility (e.g. batch sizes, learning rate, schedulers, optimizers).\n\nConfiguration and code should be completely decoupled. Parameters passed to code from a Hydra config should be in the form of primitives or dataclasses, not DictConfigs or generic key/value pairs. See, for example, the usage of the `LrScheduler` dataclass to duct-type the configuration parameters in [src/models/common.py](src/models/common.py). As as result, **all code should be able to be run independently of Hydra**. Configuration files should use [hydra instantiation](https://hydra.cc/docs/advanced/instantiate_objects/overview/) whenever possible to support this goal.\n\n### Datasets\n\nDataset preprocessing should be as minimal as possible so that the user can have maximum flexbility in how to prepare the data for their specific model or usecase. For example, rather than hardcoding data augmentations within the dataset code, data augmentations should be specified in the configuration file. Datasets should be agnostic to models, and any specific model preparation should be left to the configuration.\n\nAll datasets should be implemented within `LightningDataModule`s and inherit from `Base3dDataModule`. This data module code should handle train/test/validation splits, downloading and storing the dataset, and initializing the underlying dataset classes.\n\nDatasets should inherit from `torch_geometric.data.Dataset`, which allows the trainer to grab the number of classes and the number of features directly from the dataset object.\n\nThe `__getitem__` function of the dataset should return a `torch_geometric.data.Data` object, with at least the keys `pos` and `y`. For proper collation, keys must be Tensor objects or primitives. For all tasks, the key `pos` will be a floating point tensor of size `(n, 3)`. For classification tasks, the key `y` will be a single integer value. For segmentation tasks, the key `y` will be stored as a tensor of integers of size `(n)`.\n\nFeatures such as RGB should be stored into dedicated keys in the `Data` object. Then, these features can be added to the `x` vector dynamically by using the `AddFeatsByKey` transform.\n\n### Models\n\nMetrics should be implemented using the [TorchMetrics](https://torchmetrics.readthedocs.io/en/stable/) library whenever possible. If a metric is not available, first try to add an implementation to the TorchMetrics repo.\n\nModels should be implemented as much as possible via backend plugins, such as TorchSparse or OpenPoints. Then, construct a `LightningModule` which inherits from `BaseSegmentationModel` or `BaseClassificationModel` to interface with that backend. The backend model should be constructed in the module's initializer, and the `step` and `forward` functions should be used to transform the data into the appropriate format to pass to the backend model, apply the criterion, and return the predictions and loss.\n\n## ❤️ Contributions\n\nHave a question? Found a bug? Missing a specific feature? Feel free to file a new issue, discussion or PR with respective title and description.\n\nBefore making an issue, please verify that:\n\n- The problem still exists on the current `main` branch.\n- Your python dependencies are updated to recent versions.\n\nSuggestions for improvements are always welcome!\n\nBefore contributing, make sure you set up [pre-commit](https://pre-commit.com/):\n\n```bash\npip install pre-commit\npre-commit install\npre-commit run -a\n```\n\n## Experiment Config\n\nLocation: [configs/experiment](configs/experiment)\u003cbr\u003e\nExperiment configs allow you to overwrite parameters from main config.\u003cbr\u003e\nFor example, you can use them to version control best hyperparameters for each combination of model and dataset.\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cb\u003eShow example experiment config\u003c/b\u003e\u003c/summary\u003e\n\n```yaml\n# @package _global_\n\n# to execute this experiment run:\n# python train.py experiment=example\n\ndefaults:\n  - override /datamodule: mnist.yaml\n  - override /model: mnist.yaml\n  - override /callbacks: default.yaml\n  - override /trainer: default.yaml\n\n# all parameters below will be merged with parameters from default configurations set above\n# this allows you to overwrite only specified parameters\n\ntags: [\"mnist\", \"simple_dense_net\"]\n\nseed: 12345\n\ntrainer:\n  min_epochs: 10\n  max_epochs: 10\n  gradient_clip_val: 0.5\n\nmodel:\n  optimizer:\n    lr: 0.002\n  net:\n    lin1_size: 128\n    lin2_size: 256\n    lin3_size: 64\n\ndatamodule:\n  batch_size: 64\n\nlogger:\n  wandb:\n    tags: ${tags}\n    group: \"mnist\"\n```\n\n\u003c/details\u003e\n\n\u003cbr\u003e\n\n**Experiment design**\n\n_Say you want to execute many runs to plot how accuracy changes in respect to batch size._\n\n1. Execute the runs with some config parameter that allows you to identify them easily, like tags:\n\n   ```bash\n   python train.py -m logger=csv datamodule.batch_size=16,32,64,128 tags=[\"batch_size_exp\"]\n   ```\n\n2. Write a script or notebook that searches over the `logs/` folder and retrieves csv logs from runs containing given tags in config. Plot the results.\n\n\u003cbr\u003e\n\n## Logs\n\nHydra creates new output directory for every executed run.\n\nDefault logging structure:\n\n```\n├── logs\n│   ├── task_name\n│   │   ├── runs                        # Logs generated by single runs\n│   │   │   ├── YYYY-MM-DD_HH-MM-SS       # Datetime of the run\n│   │   │   │   ├── .hydra                  # Hydra logs\n│   │   │   │   ├── csv                     # Csv logs\n│   │   │   │   ├── wandb                   # Weights\u0026Biases logs\n│   │   │   │   ├── checkpoints             # Training checkpoints\n│   │   │   │   └── ...                     # Any other thing saved during training\n│   │   │   └── ...\n│   │   │\n│   │   └── multiruns                   # Logs generated by multiruns\n│   │       ├── YYYY-MM-DD_HH-MM-SS       # Datetime of the multirun\n│   │       │   ├──1                        # Multirun job number\n│   │       │   ├──2\n│   │       │   └── ...\n│   │       └── ...\n│   │\n│   └── debugs                          # Logs generated when debugging config is attached\n│       └── ...\n```\n\nYou can change this structure by modifying paths in [hydra configuration](configs/hydra).\n\n\u003cbr\u003e\n\n## Experiment Tracking\n\nPyTorch Lightning supports many popular logging frameworks: [Weights\u0026Biases](https://www.wandb.com/), [Neptune](https://neptune.ai/), [Comet](https://www.comet.ml/), [MLFlow](https://mlflow.org), [Tensorboard](https://www.tensorflow.org/tensorboard/).\n\nThese tools help you keep track of hyperparameters and output metrics and allow you to compare and visualize results. To use one of them simply complete its configuration in [configs/logger](configs/logger) and run:\n\n```bash\npython train.py logger=logger_name\n```\n\nYou can use many of them at once (see [configs/logger/many_loggers.yaml](configs/logger/many_loggers.yaml) for example).\n\nYou can also write your own logger.\n\nLightning provides convenient method for logging custom metrics from inside LightningModule. Read the [docs](https://pytorch-lightning.readthedocs.io/en/latest/extensions/logging.html#automatic-logging) or take a look at [MNIST example](src/models/mnist_module.py).\n\n\u003cbr\u003e\n\n## Tests\n\nTemplate comes with generic tests implemented with `pytest`.\n\n```bash\n# run all tests\npytest\n\n# run tests from specific file\npytest tests/test_train.py\n\n# run all tests except the ones marked as slow\npytest -k \"not slow\"\n```\n\nMost of the implemented tests don't check for any specific output - they exist to simply verify that executing some commands doesn't end up in throwing exceptions. You can execute them once in a while to speed up the development.\n\nCurrently, the tests cover cases like:\n\n- running 1 train, val and test step\n- running 1 epoch on 1% of data, saving ckpt and resuming for the second epoch\n- running 2 epochs on 1% of data, with DDP simulated on CPU\n\nAnd many others. You should be able to modify them easily for your use case.\n\nThere is also `@RunIf` decorator implemented, that allows you to run tests only if certain conditions are met, e.g. GPU is available or system is not windows. See the [examples](tests/test_train.py).\n\n\u003cbr\u003e\n\n## Hyperparameter Search\n\nYou can define hyperparameter search by adding new config file to [configs/hparams_search](configs/hparams_search).\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cb\u003eShow example hyperparameter search config\u003c/b\u003e\u003c/summary\u003e\n\n```yaml\n# @package _global_\n\ndefaults:\n  - override /hydra/sweeper: optuna\n\n# choose metric which will be optimized by Optuna\n# make sure this is the correct name of some metric logged in lightning module!\noptimized_metric: \"val/acc_best\"\n\n# here we define Optuna hyperparameter search\n# it optimizes for value returned from function with @hydra.main decorator\nhydra:\n  sweeper:\n    _target_: hydra_plugins.hydra_optuna_sweeper.optuna_sweeper.OptunaSweeper\n\n    # 'minimize' or 'maximize' the objective\n    direction: maximize\n\n    # total number of runs that will be executed\n    n_trials: 20\n\n    # choose Optuna hyperparameter sampler\n    # docs: https://optuna.readthedocs.io/en/stable/reference/samplers.html\n    sampler:\n      _target_: optuna.samplers.TPESampler\n      seed: 1234\n      n_startup_trials: 10 # number of random sampling runs before optimization starts\n\n    # define hyperparameter search space\n    params:\n      model.optimizer.lr: interval(0.0001, 0.1)\n      datamodule.batch_size: choice(32, 64, 128, 256)\n      model.net.lin1_size: choice(64, 128, 256)\n      model.net.lin2_size: choice(64, 128, 256)\n      model.net.lin3_size: choice(32, 64, 128, 256)\n```\n\n\u003c/details\u003e\n\nNext, execute it with: `python train.py -m hparams_search=mnist_optuna`\n\nUsing this approach doesn't require adding any boilerplate to code, everything is defined in a single config file. The only necessary thing is to return the optimized metric value from the launch file.\n\nYou can use different optimization frameworks integrated with Hydra, like [Optuna, Ax or Nevergrad](https://hydra.cc/docs/plugins/optuna_sweeper/).\n\nThe `optimization_results.yaml` will be available under `logs/task_name/multirun` folder.\n\nThis approach doesn't support advanced techniques like prunning - for more sophisticated search, you should probably write a dedicated optimization task (without multirun feature).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fclee-ai%2F3d-ml","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fclee-ai%2F3d-ml","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fclee-ai%2F3d-ml/lists"}