Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
aniketmaurya committed Dec 5, 2021
2 parents d8422a4 + 1c164cc commit ad49a30
Show file tree
Hide file tree
Showing 38 changed files with 658 additions and 208 deletions.
File renamed without changes.
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,11 @@


## Highlights

- 2021-8-25: [Released first version 0.0.1](https://pypi.org/project/gradsflow/):tada:
- 2021-8-29: Migrated to Ray Tune
- 2021-10-4: Model Trainer support
- 2021-10-5: [Hacktoberfest 2021 Kickoff event](https://youtu.be/lVtxXyCAZ-4?t=2647)
- 2021-10-7: [v0.0.6 Release blog post](https://towardsdatascience.com/gradsflow-democratizing-ai-with-automl-9a8a75d6b7ea)
- 2021-10-5: [Hacktoberfest 2021 Kickoff event](https://youtu.be/lVtxXyCAZ-4?t=2647)
- 2021-10-4: Model Trainer support
- 2021-8-29: Migrated to Ray Tune
- 2021-8-25: [Released first version 0.0.1](https://pypi.org/project/gradsflow/):tada:

## Installation

Expand Down
100 changes: 67 additions & 33 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,48 +1,82 @@
# Release Notes

## 0.0.1 - 2021-8-25
## 0.0.7 - 2021-11-26
* ☄️ comet integration [#129](https://github.com/gradsflow/gradsflow/pull/129)
* add model checkpoint callback [#121](https://github.com/gradsflow/gradsflow/pull/121)
* 📝 add csv logger [#116](https://github.com/gradsflow/gradsflow/pull/116)
* 🚀 add train_eval_callback [#111](https://github.com/gradsflow/gradsflow/pull/111)
* 🪄 add Average Meter [#109](https://github.com/gradsflow/gradsflow/pull/109)
* fix device issue in metric calculation PR [#106](https://github.com/gradsflow/gradsflow/pull/106)

* 📝 update example and documentation. Done by [ aniketmaurya](https://github.com/aniketmaurya). Check the [Pull Request 20 with the changes and stuff](https://github.com/gradsflow/gradsflow/pull/20).
* :tada::sparkles: First Release - v0.0.1 - Refactor API & tested Python 3.7+. Done by [ aniketmaurya](https://github.com/aniketmaurya). Check the [Pull Request 18 with the changes and stuff](https://github.com/gradsflow/gradsflow/pull/18).
* Adding example notebook for AutoSummarization. Done by [the GitHub user gagan3012](https://github.com/gagan3012). Check the [Pull Request 19 with the changes and stuff](https://github.com/gradsflow/gradsflow/pull/19).
* Adding text summarisation. Done by [the GitHub user gagan3012](https://github.com/gagan3012). Check the [Pull Request 14 with the changes and stuff](https://github.com/gradsflow/gradsflow/pull/14).
* add codecov CI. Done by [the GitHub user aniketmaurya](https://github.com/aniketmaurya). Check the [Pull Request 15 with the changes and stuff](https://github.com/gradsflow/gradsflow/pull/15).
* 📚 update documentation - added citation, acknowledgments, docstrings automation. Done by [the GitHub user aniketmaurya](https://github.com/aniketmaurya). Check the [Pull Request 13 with the changes and stuff](https://github.com/gradsflow/gradsflow/pull/13).
* Refactor API Design, CI & Docs PR [#10](https://github.com/gradsflow/gradsflow/pull/10) by [@aniketmaurya](https://github.com/aniketmaurya).
* auto docstring. PR [#7](https://github.com/gradsflow/gradsflow/pull/7) by [@aniketmaurya](https://github.com/aniketmaurya).
* Add AutoImageClassifier. PR [#1](https://github.com/gradsflow/gradsflow/pull/1) by [@aniketmaurya](https://github.com/aniketmaurya).

## 0.0.2 - 2021-8-27
## 0.0.6 - 2021-10-4

* Fix max steps validation key error. PR [#31](https://github.com/gradsflow/gradsflow/pull/31) by [@aniketmaurya](https://github.com/aniketmaurya).
* 🎉 Revamp Callbacks and Training. PR [#94](https://github.com/gradsflow/gradsflow/pull/94)
* ✨ refactor data handling 📝 docs update. PR [#91](https://github.com/gradsflow/gradsflow/pull/91)
* integrate torchmetrics. PR [#80](https://github.com/gradsflow/gradsflow/pull/80)
* callbacks & 🤑 ProgressCallback. PR [#76](https://github.com/gradsflow/gradsflow/pull/76)
* 🔥 Add AutoModel Tuner. PR [#74](https://github.com/gradsflow/gradsflow/pull/74)
* refactor APIs - Simplify API & add `model.compile(...)`. PR [#73](https://github.com/gradsflow/gradsflow/pull/73)
* 🤗 integrate HF Accelerator. PR [#71](https://github.com/gradsflow/gradsflow/pull/71)

## 0.0.3 - 2021-8-31
## 0.0.5 - 2021-9-26

* add optuna visualizations 🎨 . PR [#27](https://github.com/gradsflow/gradsflow/pull/27) by [@aniketmaurya](https://github.com/aniketmaurya).
* add max_steps for HPO. PR [#25](https://github.com/gradsflow/gradsflow/pull/25) by [@aniketmaurya](https://github.com/aniketmaurya).
* :memo: update docs & license. PR [#23](https://github.com/gradsflow/gradsflow/pull/23) by [@aniketmaurya](https://github.com/aniketmaurya).
* fetch best trial model. PR [#21](https://github.com/gradsflow/gradsflow/pull/21) by [@aniketmaurya](https://github.com/aniketmaurya).
* migrate to ray_tune 🌟. Read more [here](https://github.com/gradsflow/gradsflow/issues/35). PR [#36](https://github.com/gradsflow/gradsflow/pull/36) by [@aniketmaurya](https://github.com/aniketmaurya).
* render jupyter notebooks in documentation. PR [#38](https://github.com/gradsflow/gradsflow/pull/38) by [@aniketmaurya](https://github.com/aniketmaurya).
* 🔥 Add custom training loop with `model.fit`. PR [#63](https://github.com/gradsflow/gradsflow/pull/63) Done
by [@aniketmaurya](https://github.com/aniketmaurya)
* ☁️ Add `ray.data` - remote dataset loader. PR [#61](https://github.com/gradsflow/gradsflow/pull/61) Done
by [@aniketmaurya](https://github.com/aniketmaurya)
* 🎉 Add AutoDataset - Encapsulate datamodule and dataloaders. PR [#59](https://github.com/gradsflow/gradsflow/pull/59)
Done by [@aniketmaurya](https://github.com/aniketmaurya)
* 🌟 Add Autotask feature. PR [#54](https://github.com/gradsflow/gradsflow/pull/54) Done
by [@gagan3012](https://github.com/gagan3012)
* ✨ Add AutoTrainer to support plain torch training loop and other torch frameworks.
PR [#53](https://github.com/gradsflow/gradsflow/pull/53)

## 0.0.4 - 2021-9-3

* fix best checkpoints model loading. PR [#52](https://github.com/gradsflow/gradsflow/pull/52)
* 🚀 feature/fix train arguments docs PR [#44](https://github.com/gradsflow/gradsflow/pull/44)
* Publish Python 🐍 distributions 📦 to PyPI [#42](https://github.com/gradsflow/gradsflow/pull/42)

## 0.0.5 - 2021-9-26
* 🔥 Add custom training loop with `model.fit`. PR [#63](https://github.com/gradsflow/gradsflow/pull/63) Done by [@aniketmaurya](https://github.com/aniketmaurya)
* ☁️ Add `ray.data` - remote dataset loader. PR [#61](https://github.com/gradsflow/gradsflow/pull/61) Done by [@aniketmaurya](https://github.com/aniketmaurya)
* 🎉 Add AutoDataset - Encapsulate datamodule and dataloaders. PR [#59](https://github.com/gradsflow/gradsflow/pull/59) Done by [@aniketmaurya](https://github.com/aniketmaurya)
* 🌟 Add Autotask feature. PR [#54](https://github.com/gradsflow/gradsflow/pull/54) Done by [@gagan3012](https://github.com/gagan3012)
* ✨ Add AutoTrainer to support plain torch training loop and other torch frameworks. PR [#53](https://github.com/gradsflow/gradsflow/pull/53)
## 0.0.3 - 2021-8-31

* add optuna visualizations 🎨 . PR [#27](https://github.com/gradsflow/gradsflow/pull/27)
by [@aniketmaurya](https://github.com/aniketmaurya).
* add max_steps for HPO. PR [#25](https://github.com/gradsflow/gradsflow/pull/25)
by [@aniketmaurya](https://github.com/aniketmaurya).
* :memo: update docs & license. PR [#23](https://github.com/gradsflow/gradsflow/pull/23)
by [@aniketmaurya](https://github.com/aniketmaurya).
* fetch best trial model. PR [#21](https://github.com/gradsflow/gradsflow/pull/21)
by [@aniketmaurya](https://github.com/aniketmaurya).
* migrate to ray_tune 🌟. Read more [here](https://github.com/gradsflow/gradsflow/issues/35).
PR [#36](https://github.com/gradsflow/gradsflow/pull/36) by [@aniketmaurya](https://github.com/aniketmaurya).
* render jupyter notebooks in documentation. PR [#38](https://github.com/gradsflow/gradsflow/pull/38)
by [@aniketmaurya](https://github.com/aniketmaurya).

## 0.0.6 - 2021-10-4
* 🎉 Revamp Callbacks and Training. PR [#94](https://github.com/gradsflow/gradsflow/pull/94)
* ✨ refactor data handling 📝 docs update. PR [#91](https://github.com/gradsflow/gradsflow/pull/91)
* integrate torchmetrics. PR [#80](https://github.com/gradsflow/gradsflow/pull/80)
* callbacks & 🤑 ProgressCallback. PR [#76](https://github.com/gradsflow/gradsflow/pull/76)
* 🔥 Add AutoModel Tuner. PR [#74](https://github.com/gradsflow/gradsflow/pull/74)
* refactor APIs - Simplify API & add `model.compile(...)`. PR [#73](https://github.com/gradsflow/gradsflow/pull/73)
* 🤗 integrate HF Accelerator. PR [#71](https://github.com/gradsflow/gradsflow/pull/71)
## 0.0.2 - 2021-8-27

* Fix max steps validation key error. PR [#31](https://github.com/gradsflow/gradsflow/pull/31)
by [@aniketmaurya](https://github.com/aniketmaurya).

## 0.0.1 - 2021-8-25

* 📝 update example and documentation. Done by [ aniketmaurya](https://github.com/aniketmaurya). Check
the [Pull Request 20 with the changes and stuff](https://github.com/gradsflow/gradsflow/pull/20).
* :tada::sparkles: First Release - v0.0.1 - Refactor API & tested Python 3.7+. Done
by [ aniketmaurya](https://github.com/aniketmaurya). Check
the [Pull Request 18 with the changes and stuff](https://github.com/gradsflow/gradsflow/pull/18).
* Adding example notebook for AutoSummarization. Done by [the GitHub user gagan3012](https://github.com/gagan3012).
Check the [Pull Request 19 with the changes and stuff](https://github.com/gradsflow/gradsflow/pull/19).
* Adding text summarisation. Done by [the GitHub user gagan3012](https://github.com/gagan3012). Check
the [Pull Request 14 with the changes and stuff](https://github.com/gradsflow/gradsflow/pull/14).
* add codecov CI. Done by [the GitHub user aniketmaurya](https://github.com/aniketmaurya). Check
the [Pull Request 15 with the changes and stuff](https://github.com/gradsflow/gradsflow/pull/15).
* 📚 update documentation - added citation, acknowledgments, docstrings automation. Done
by [the GitHub user aniketmaurya](https://github.com/aniketmaurya). Check
the [Pull Request 13 with the changes and stuff](https://github.com/gradsflow/gradsflow/pull/13).
* Refactor API Design, CI & Docs PR [#10](https://github.com/gradsflow/gradsflow/pull/10)
by [@aniketmaurya](https://github.com/aniketmaurya).
* auto docstring. PR [#7](https://github.com/gradsflow/gradsflow/pull/7)
by [@aniketmaurya](https://github.com/aniketmaurya).
* Add AutoImageClassifier. PR [#1](https://github.com/gradsflow/gradsflow/pull/1)
by [@aniketmaurya](https://github.com/aniketmaurya).
9 changes: 4 additions & 5 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,11 @@


## Highlights

- 2021-8-25: [Released first version 0.0.1](https://pypi.org/project/gradsflow/):tada:
- 2021-8-29: Migrated to Ray Tune
- 2021-10-4: Model Trainer support
- 2021-10-5: [Hacktoberfest 2021 Kickoff event](https://youtu.be/lVtxXyCAZ-4?t=2647)
- 2021-10-7: [v0.0.6 Release blog post](https://towardsdatascience.com/gradsflow-democratizing-ai-with-automl-9a8a75d6b7ea)
- 2021-10-5: [Hacktoberfest 2021 Kickoff event](https://youtu.be/lVtxXyCAZ-4?t=2647)
- 2021-10-4: Model Trainer support
- 2021-8-29: Migrated to Ray Tune
- 2021-8-25: [Released first version 0.0.1](https://pypi.org/project/gradsflow/):tada:

## Installation

Expand Down
2 changes: 2 additions & 0 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ tags-macros-plugin @ git+https://github.com/jldiaz/mkdocs-plugin-tags.git@d26e2f
mkdocs-jupyter>=0.18.0
mkdocs-meta-descriptions-plugin
jupyter_contrib_nbextensions
comet_ml
lightning-flash[image,text]>=0.5.1
20 changes: 17 additions & 3 deletions examples/src/models/hello_world.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,20 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import os

import torchvision
from timm import create_model
from torch.utils.data import DataLoader
from torchvision import transforms as T

from gradsflow import AutoDataset, Model
from gradsflow.callbacks import CSVLogger
from gradsflow.callbacks import (
CometCallback,
CSVLogger,
EmissionTrackerCallback,
ModelCheckpoint,
)
from gradsflow.data.common import random_split_dataset

# Replace dataloaders with your custom dataset and you are all set to train your model
Expand All @@ -32,7 +39,14 @@
train_dl = DataLoader(train_data, batch_size=batch_size)
val_dl = DataLoader(val_data, batch_size=batch_size)
num_classes = len(data.categories)
csv_logger = CSVLogger(verbose=True)
cbs = [
CSVLogger(
verbose=True,
),
ModelCheckpoint(),
EmissionTrackerCallback(),
CometCallback(offline=False),
]

if __name__ == "__main__":
autodataset = AutoDataset(train_dl, val_dl, num_classes=num_classes)
Expand All @@ -41,4 +55,4 @@
model = Model(cnn)

model.compile("crossentropyloss", "adam", metrics=["accuracy"])
model.fit(autodataset, max_epochs=10, steps_per_epoch=10, callbacks=csv_logger)
model.fit(autodataset, max_epochs=10, steps_per_epoch=10, callbacks=cbs)
3 changes: 2 additions & 1 deletion gradsflow/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from os import environ as _environ

_environ["LOGURU_LEVEL"] = _environ.get("LOGURU_LEVEL") or _environ.get("LOG_LEVEL", "ERROR")
_environ["COMET_DISABLE_AUTO_LOGGING"] = "1"

from gradsflow.core.automodel import AutoModel
from gradsflow.data import AutoDataset
Expand All @@ -28,4 +29,4 @@
from gradsflow.tuner.automodel import AutoModelV2
from gradsflow.tuner.tuner import Tuner

__version__ = "0.0.7.dev1"
__version__ = "0.0.7.post1"
5 changes: 4 additions & 1 deletion gradsflow/callbacks/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from .callbacks import Callback
from .logger import CSVLogger
from .export import ModelCheckpoint
from .gpu import EmissionTrackerCallback
from .logger import CometCallback, CSVLogger
from .progress import ProgressCallback
from .raytune import report_checkpoint_callback
from .runner import CallbackRunner
from .training import TrainEvalCallback
4 changes: 3 additions & 1 deletion gradsflow/callbacks/callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import typing
from abc import ABC
from typing import Callable, Optional

if typing.TYPE_CHECKING:
Expand All @@ -22,10 +23,11 @@ def dummy(x=None, *_, **__):
return x


class Callback:
class Callback(ABC):
"""Callback objects define events on which it will run during the model training cycle."""

_events = ("forward", "step", "train_epoch", "val_epoch", "epoch", "fit")
_name: str = "Callback"

def __init__(self, model: Optional["Model"]):
self.model = model
Expand Down
39 changes: 39 additions & 0 deletions gradsflow/callbacks/export.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Copyright (c) 2021 GradsFlow. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import os
from pathlib import Path
from typing import Optional

from gradsflow.callbacks.callbacks import Callback


class ModelCheckpoint(Callback):
def __init__(self, filename: Optional[str] = None, path: str = os.getcwd(), save_extra: bool = False):
"""
Saves Model checkpoint
Args:
filename: name of checkpoint
path: folder path location of the model checkpoint
save_extra: whether to save extra details like tracker
"""
super().__init__(model=None)
filename = filename or "model"
self.path = path
self._dst = Path(path) / Path(filename)
self.save_extra = save_extra

def on_epoch_end(self):
epoch = self.model.tracker.current_epoch
path = f"{self._dst}_epoch={epoch}_.pt"
self.model.save(path, save_extra=self.save_extra)
49 changes: 49 additions & 0 deletions gradsflow/callbacks/gpu.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Copyright (c) 2021 GradsFlow. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from loguru import logger

from gradsflow.callbacks import Callback
from gradsflow.utility.imports import requires


class EmissionTrackerCallback(Callback):
"""
Tracks the carbon emissions produced by deep neural networks using
[CodeCarbon](https://github.com/mlco2/codecarbon). To use this callback first install codecarbon using
`pip install codecarbon`.
For offline use, you must have to specify the [country code](https://github.com/mlco2/codecarbon#offline-mode).
Args:
offline: whether to use internet connection or not. You will have to provide the country code `country_iso_code` for offline use.
**kwargs: passed directly to codecarbon class.
"""

_name = "EmissionTrackerCallback"

@requires("codecarbon", "install codecarbon to use EmissionTrackerCallback")
def __init__(self, offline: bool = False, **kwargs):
from codecarbon import EmissionsTracker, OfflineEmissionsTracker

if offline:
self._emission_tracker = OfflineEmissionsTracker(**kwargs)
else:
self._emission_tracker = EmissionsTracker(**kwargs)
self._emission_tracker.start()

super().__init__(model=None)

def on_fit_end(self):
emissions: float = self._emission_tracker.stop()
logger.info(f"Emissions: {emissions} kg")
15 changes: 15 additions & 0 deletions gradsflow/callbacks/logger/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright (c) 2021 GradsFlow. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from .comet import CometCallback
from .logger import CSVLogger

0 comments on commit ad49a30

Please sign in to comment.