Skip to content

Commit

Permalink
baseversion support added
Browse files Browse the repository at this point in the history
  • Loading branch information
Maitreyapatel committed Nov 18, 2022
1 parent 63153fa commit 954731b
Show file tree
Hide file tree
Showing 57 changed files with 1,440 additions and 2 deletions.
25 changes: 24 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ celerybeat.pid
*.sage.py

# Environments
.env
.venv
env/
venv/
Expand All @@ -127,3 +126,27 @@ dmypy.json

# Pyre type checker
.pyre/

### VisualStudioCode
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
*.code-workspace
**/.vscode

# JetBrains
.idea/

# Data & Models
*.h5
*.tar
*.tar.gz

# Lightning-Hydra-Template
configs/local/default.yaml
data/
logs/
.env
.autoenv
122 changes: 122 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
default_language_version:
python: python3

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
hooks:
# list of supported hooks: https://pre-commit.com/hooks.html
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-docstring-first
- id: check-yaml
- id: debug-statements
- id: detect-private-key
- id: check-executables-have-shebangs
- id: check-toml
- id: check-case-conflict
- id: check-added-large-files

# python code formatting
- repo: https://github.com/psf/black
rev: 22.6.0
hooks:
- id: black
args: [--line-length, "99"]

# python import sorting
- repo: https://github.com/PyCQA/isort
rev: 5.10.1
hooks:
- id: isort
args: ["--profile", "black", "--filter-files"]

# python upgrading syntax to newer version
- repo: https://github.com/asottile/pyupgrade
rev: v2.32.1
hooks:
- id: pyupgrade
args: [--py38-plus]

# python docstring formatting
- repo: https://github.com/myint/docformatter
rev: v1.4
hooks:
- id: docformatter
args: [--in-place, --wrap-summaries=99, --wrap-descriptions=99]

# python check (PEP8), programming errors and code complexity
- repo: https://github.com/PyCQA/flake8
rev: 4.0.1
hooks:
- id: flake8
args:
[
"--extend-ignore",
"E203,E402,E501,F401,F841",
"--exclude",
"logs/*,data/*",
]

# python security linter
- repo: https://github.com/PyCQA/bandit
rev: "1.7.1"
hooks:
- id: bandit
args: ["-s", "B101"]

# yaml formatting
- repo: https://github.com/pre-commit/mirrors-prettier
rev: v2.7.1
hooks:
- id: prettier
types: [yaml]

# shell scripts linter
- repo: https://github.com/shellcheck-py/shellcheck-py
rev: v0.8.0.4
hooks:
- id: shellcheck

# md formatting
- repo: https://github.com/executablebooks/mdformat
rev: 0.7.14
hooks:
- id: mdformat
args: ["--number"]
additional_dependencies:
- mdformat-gfm
- mdformat-tables
- mdformat_frontmatter
# - mdformat-toc
# - mdformat-black

# word spelling linter
- repo: https://github.com/codespell-project/codespell
rev: v2.1.0
hooks:
- id: codespell
args:
- --skip=logs/**,data/**,*.ipynb
# - --ignore-words-list=abc,def

# jupyter notebook cell output clearing
- repo: https://github.com/kynan/nbstripout
rev: 0.5.0
hooks:
- id: nbstripout

# jupyter notebook linting
- repo: https://github.com/nbQA-dev/nbQA
rev: 1.4.0
hooks:
- id: nbqa-black
args: ["--line-length=99"]
- id: nbqa-isort
args: ["--profile=black"]
- id: nbqa-flake8
args:
[
"--extend-ignore=E203,E402,E501,F401,F841",
"--exclude=logs/*,data/*",
]
27 changes: 27 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

help: ## Show help
@grep -E '^[.a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'

clean: ## Clean autogenerated files
rm -rf dist
find . -type f -name "*.DS_Store" -ls -delete
find . | grep -E "(__pycache__|\.pyc|\.pyo)" | xargs rm -rf
find . | grep -E ".pytest_cache" | xargs rm -rf
find . | grep -E ".ipynb_checkpoints" | xargs rm -rf
rm -f .coverage

clean-logs: ## Clean logs
rm -r logs/**

style: ## Run pre-commit hooks
pre-commit run -a

sync: ## Merge changes from develop branch to your current branch
git fetch --all
git merge develop

test: ## Run not slow tests
pytest -k "not slow"

test-full: ## Run all tests
pytest
58 changes: 57 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,58 @@
<div align="center">

# reliability-score
NLP tool for wide-range model evaluations

<a href="https://pytorch.org/get-started/locally/"><img alt="PyTorch" src="https://img.shields.io/badge/PyTorch-ee4c2c?logo=pytorch&logoColor=white"></a>
<a href="https://pytorchlightning.ai/"><img alt="Lightning" src="https://img.shields.io/badge/-Lightning-792ee5?logo=pytorchlightning&logoColor=white"></a>
<a href="https://hydra.cc/"><img alt="Config: Hydra" src="https://img.shields.io/badge/Config-Hydra-89b8cd"></a>
<a href="https://github.com/ashleve/lightning-hydra-template"><img alt="Template" src="https://img.shields.io/badge/-Lightning--Hydra--Template-017F2F?style=flat&logo=github&labelColor=gray"></a><br>
[![Paper](http://img.shields.io/badge/paper-arxiv.1001.2234-B31B1B.svg)](https://www.nature.com/articles/nature14539)
[![Conference](http://img.shields.io/badge/AnyConference-year-4b44ce.svg)](https://papers.nips.cc/paper/2020)

</div>

## Description

What it does

## How to run

Install dependencies

```bash
# clone project
git clone https://github.com/YourGithubName/your-repo-name
cd your-repo-name

# [OPTIONAL] create conda environment
conda create -n myenv python=3.8
conda activate myenv

# install pytorch according to instructions
# https://pytorch.org/get-started/

# install requirements
pip install -r requirements.txt
```

Train model with default configuration

```bash
# train on CPU
python src/test.py trainer=cpu

# train on GPU
python src/test.py trainer=gpu
```

Train model with chosen experiment configuration from [configs/experiment/](configs/experiment/)

```bash
python src/test.py experiment=experiment_name.yaml
```

You can override any parameter from command line like this

```bash
python src/test.py datamodule.batch_size=64
```
3 changes: 3 additions & 0 deletions configs/callbacks/acc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
accuracy_callback:
_target_: src.callbacks.evals.discriminative.AccuracyMetric
monitor: "all"
4 changes: 4 additions & 0 deletions configs/callbacks/default.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
defaults:
- rich_progress_bar.yaml
- _self_

4 changes: 4 additions & 0 deletions configs/callbacks/mnli.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
defaults:
- default.yaml
- acc.yaml

6 changes: 6 additions & 0 deletions configs/callbacks/rich_progress_bar.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# https://pytorch-lightning.readthedocs.io/en/latest/api/pytorch_lightning.callbacks.RichProgressBar.html

# Create a progress bar with rich text formatting.
# Look at the above link for more detailed information.
rich_progress_bar:
_target_: pytorch_lightning.callbacks.RichProgressBar
5 changes: 5 additions & 0 deletions configs/custom_model/bert_base_uncased.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
model_name: "ishan/bert-base-uncased-mnli"
tokenizer:
model_name: "ishan/bert-base-uncased-mnli"
args:
truncation: true
6 changes: 6 additions & 0 deletions configs/datamodule/mnli.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
_target_: src.datamodules.mnli_datamodule.MNLIDataModule
data_dir: ${paths.data_dir}
batch_size: 1
num_workers: 0
pin_memory: False
tokenizer_data: ${custom_model.tokenizer}
19 changes: 19 additions & 0 deletions configs/eval.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# @package _global_

defaults:
- _self_
- callbacks: default.yaml
- datamodule: mnli.yaml # choose datamodule with `test_dataloader()` for evaluation
- model: inference.yaml
- logger: null
- trainer: default.yaml
- paths: default.yaml
- extras: default.yaml
- hydra: default.yaml
- custom_model: bert_base_uncased.yaml

- experiment: null

task_name: "eval"

tags: ["dev"]
18 changes: 18 additions & 0 deletions configs/experiment/example.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# @package _global_

# to execute this experiment run:
# python train.py experiment=example

defaults:
- override /datamodule: mnli.yaml
- override /model: inference.yaml
- override /callbacks: mnli.yaml
- override /trainer: default.yaml
- override /custom_model: bert_base_uncased.yaml

# all parameters below will be merged with parameters from default configurations set above
# this allows you to overwrite only specified parameters

tags: ["mnli", "test"]

seed: 42
8 changes: 8 additions & 0 deletions configs/extras/default.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# disable python warnings if they annoy you
ignore_warnings: False

# ask user for tags if none are provided in the config
enforce_tags: True

# pretty print config tree at the start of the run using Rich library
print_config: True
13 changes: 13 additions & 0 deletions configs/hydra/default.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# https://hydra.cc/docs/configure_hydra/intro/

# enable color logging
defaults:
- override hydra_logging: colorlog
- override job_logging: colorlog

# output directory, generated dynamically on each run
run:
dir: ${paths.log_dir}/${task_name}/runs/${now:%Y-%m-%d}_${now:%H-%M-%S}
sweep:
dir: ${paths.log_dir}/${task_name}/multiruns/${now:%Y-%m-%d}_${now:%H-%M-%S}
subdir: ${hydra.job.num}
Empty file added configs/local/.gitkeep
Empty file.
12 changes: 12 additions & 0 deletions configs/logger/comet.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# https://www.comet.ml

comet:
_target_: pytorch_lightning.loggers.comet.CometLogger
api_key: ${oc.env:COMET_API_TOKEN} # api key is loaded from environment variable
save_dir: "${paths.output_dir}"
project_name: "lightning-hydra-template"
rest_api_key: null
# experiment_name: ""
experiment_key: null # set to resume experiment
offline: False
prefix: ""
7 changes: 7 additions & 0 deletions configs/logger/csv.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# csv logger built in lightning

csv:
_target_: pytorch_lightning.loggers.csv_logs.CSVLogger
save_dir: "${paths.output_dir}"
name: "csv/"
prefix: ""
9 changes: 9 additions & 0 deletions configs/logger/many_loggers.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# train with many loggers at once

defaults:
# - comet.yaml
- csv.yaml
# - mlflow.yaml
# - neptune.yaml
- tensorboard.yaml
- wandb.yaml
12 changes: 12 additions & 0 deletions configs/logger/mlflow.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# https://mlflow.org

mlflow:
_target_: pytorch_lightning.loggers.mlflow.MLFlowLogger
# experiment_name: ""
# run_name: ""
tracking_uri: ${paths.log_dir}/mlflow/mlruns # run `mlflow ui` command inside the `logs/mlflow/` dir to open the UI
tags: null
# save_dir: "./mlruns"
prefix: ""
artifact_location: null
# run_id: ""
9 changes: 9 additions & 0 deletions configs/logger/neptune.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# https://neptune.ai

neptune:
_target_: pytorch_lightning.loggers.neptune.NeptuneLogger
api_key: ${oc.env:NEPTUNE_API_TOKEN} # api key is loaded from environment variable
project: username/lightning-hydra-template
# name: ""
log_model_checkpoints: True
prefix: ""
Loading

0 comments on commit 954731b

Please sign in to comment.