Skip to content

Commit

Permalink
🤩 refactor core (#136)
Browse files Browse the repository at this point in the history
* refactor core AutoModel

* rename task to autotask

* ignore test init

* update docs
  • Loading branch information
aniketmaurya authored Dec 7, 2021
1 parent d264567 commit 3fe670e
Show file tree
Hide file tree
Showing 32 changed files with 100 additions and 57 deletions.
3 changes: 3 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@ exclude_lines =
raise NotImplementedError
if 0:
if __name__ == .__main__.:

omit =
tests/__init__.py
9 changes: 9 additions & 0 deletions docs/gradsflow/autotasks/autotasks.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
::: gradsflow.autotasks.autotasks

---

::: gradsflow.autotasks.autoclassification

---

::: gradsflow.autotasks.autosummarization
9 changes: 9 additions & 0 deletions docs/gradsflow/autotasks/engine.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
::: gradsflow.autotasks.engine.backend

---

::: gradsflow.autotasks.engine.automodel

---

::: gradsflow.autotasks.engine.autoclassifier
12 changes: 0 additions & 12 deletions docs/gradsflow/core.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,3 @@
Core Building blocks for AutoML Tasks

::: gradsflow.core.base

---

::: gradsflow.core.backend

---

::: gradsflow.core.automodel

---

::: gradsflow.core.autoclassifier
9 changes: 0 additions & 9 deletions docs/gradsflow/tasks.md

This file was deleted.

2 changes: 0 additions & 2 deletions docs/gradsflow/tuner.md
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
## 🚨 Experimental

::: gradsflow.tuner
2 changes: 1 addition & 1 deletion examples/src/models/hello_world.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
),
ModelCheckpoint(),
EmissionTrackerCallback(),
CometCallback(offline=False),
CometCallback(offline=True),
]

if __name__ == "__main__":
Expand Down
13 changes: 6 additions & 7 deletions gradsflow/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,15 @@
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.autotasks.autoclassification.image import AutoImageClassifier
from gradsflow.autotasks.autoclassification.text import AutoTextClassifier
from gradsflow.autotasks.autosummarization import AutoSummarization
from gradsflow.autotasks.autotasks import autotask, available_tasks
from gradsflow.autotasks.engine.automodel import AutoModel
from gradsflow.data import AutoDataset
from gradsflow.models.model import Model
from gradsflow.tasks.autoclassification.image import AutoImageClassifier
from gradsflow.tasks.autoclassification.text import AutoTextClassifier
from gradsflow.tasks.autosummarization import AutoSummarization
from gradsflow.tasks.autotasks import autotask, available_tasks
from gradsflow.tuner.automodel import AutoModelV2
from gradsflow.tuner.tuner import Tuner

__version__ = "0.0.7.post1"
__version__ = "0.0.8.dev0"
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

import timm

from gradsflow.core.autoclassifier import AutoClassifier
from gradsflow.core.backend import Backend
from gradsflow.autotasks.engine.autoclassifier import AutoClassifier
from gradsflow.autotasks.engine.backend import Backend
from gradsflow.models.model import Model


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

import torch

from gradsflow.core.autoclassifier import AutoClassifier
from gradsflow.autotasks.engine.autoclassifier import AutoClassifier


# noinspection PyTypeChecker
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

import torch

from gradsflow.core.autoclassifier import AutoClassifier
from gradsflow.autotasks.engine.autoclassifier import AutoClassifier


# noinspection PyTypeChecker
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@


def available_tasks() -> List[str]:
"""Get a list of all available tasks."""
"""Get a list of all available autotasks."""
return list(SUPPORTED_TASKS.keys())


Expand All @@ -60,7 +60,7 @@ def autotask(
train_dataloader Optional[DataLoader]: torch dataloader
val_dataloader Optional[DataLoader]: torch dataloader
num_classes Optional[int]: number of classes
task Optional[str]: type of task. Check available tasks `availalbe_tasks()
task Optional[str]: type of task. Check available autotasks `availalbe_tasks()
data_type Optional[str]: default=None. type of data - image, text or infer.
max_epochs [int]: default=10.
n_trials [int]: default=100.
Expand All @@ -77,7 +77,7 @@ def autotask(
raise UserWarning("either task or data_type must be set!")

if task not in SUPPORTED_TASKS:
raise UserWarning(f"Unknown task {task}, available tasks are {list(SUPPORTED_TASKS.keys())}")
raise UserWarning(f"Unknown task {task}, available autotasks are {list(SUPPORTED_TASKS.keys())}")

targeted_task = SUPPORTED_TASKS[task]

Expand Down
13 changes: 13 additions & 0 deletions gradsflow/autotasks/engine/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# 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.
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
# limitations under the License.

from abc import abstractmethod
from typing import TYPE_CHECKING, Dict, List, Optional, Union
from typing import Dict, List, Optional, Union

import torch
from ray import tune
from torch.utils.data import DataLoader

from gradsflow.core.automodel import AutoModel
from gradsflow.autotasks.engine.automodel import AutoModel
from gradsflow.utility.common import listify
from gradsflow.utility.imports import is_installed

Expand All @@ -29,7 +29,7 @@


class AutoClassifier(AutoModel):
"""Implements `AutoModel` for classification tasks."""
"""Implements `AutoModel` for classification autotasks."""

_DEFAULT_BACKBONES = []

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from ray import tune
from torch.utils.data import DataLoader

from gradsflow.core.backend import AutoBackend
from gradsflow.autotasks.engine.backend import AutoBackend
from gradsflow.core.base import BaseAutoModel
from gradsflow.data import AutoDataset
from gradsflow.utility.common import module_to_cls_index
Expand All @@ -36,7 +36,7 @@
class AutoModel(BaseAutoModel, ABC):
"""
Base model that defines hyperparameter search methods and initializes `Ray`.
All other tasks are implementation of `AutoModel`.
All other autotasks are implementation of `AutoModel`.
Args:
datamodule flash.DataModule: DataModule from Flash or PyTorch Lightning
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,18 @@
# 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.
#
# 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 logging
import math
Expand Down
2 changes: 2 additions & 0 deletions gradsflow/callbacks/logger/comet.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import os

os.environ["COMET_DISABLE_AUTO_LOGGING"] = "1"
from typing import TYPE_CHECKING, Optional

BaseExperiment = None
Expand Down
1 change: 0 additions & 1 deletion gradsflow/callbacks/progress.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
from typing import Dict, Optional

from rich.progress import BarColumn, Progress, RenderableColumn, TimeRemainingColumn
from rich.table import Column

from .callbacks import Callback

Expand Down
2 changes: 1 addition & 1 deletion gradsflow/data/autodata.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# 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 typing import TYPE_CHECKING, Callable, Optional
from typing import Callable, Optional

from accelerate import Accelerator
from loguru import logger
Expand Down
4 changes: 3 additions & 1 deletion mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ nav:
- gradsflow/models/model.md
- gradsflow/models/tracker.md
- Tuner: gradsflow/tuner
- AutoTasks: gradsflow/tasks
- AutoTasks:
- gradsflow/autotasks/autotasks.md
- gradsflow/autotasks/engine.md
- Data: gradsflow/data
- Callbacks: gradsflow/callbacks
- utility: gradsflow/utility.md
Expand Down
6 changes: 6 additions & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,14 @@
# limitations under the License.

import os
import sys
import warnings

try:
import gradsflow
except ImportError:
sys.path.append("./")

os.environ["GF_CI"] = "true"

warnings.filterwarnings("ignore")
13 changes: 13 additions & 0 deletions tests/autotasks/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# 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.
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
import ray
from flash.image import ImageClassificationData

from gradsflow.autotasks import autotask
from gradsflow.data.image import image_dataset_from_directory
from gradsflow.models.model import Model
from gradsflow.tasks import autotask

warnings.filterwarnings("ignore")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@

import pytest

from gradsflow.core.backend import AutoBackend
from gradsflow.autotasks.engine.backend import AutoBackend

trainer_config = {"show_progress": False}


@patch("gradsflow.core.backend.pl")
@patch("gradsflow.autotasks.engine.backend.pl")
def test_optimization_objective(mock_pl: Mock):
dm = MagicMock()
model_builder = MagicMock()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
import torch
from flash.image import ImageClassificationData

from gradsflow.core.automodel import AutoModel
from gradsflow.core.backend import Backend
from gradsflow.autotasks.engine.automodel import AutoModel
from gradsflow.autotasks.engine.backend import Backend

cwd = Path.cwd()
datamodule = ImageClassificationData.from_folders(
Expand Down Expand Up @@ -49,7 +49,7 @@ def test_create_search_space():


@patch.multiple(AutoModel, __abstractmethods__=set())
@patch("gradsflow.core.backend.pl")
@patch("gradsflow.autotasks.engine.backend.pl")
def test_objective(mock_pl):
optimization_metric = "val_accuracy"
model = AutoModel(
Expand All @@ -66,7 +66,7 @@ def test_objective(mock_pl):


@patch.multiple(AutoModel, __abstractmethods__=set())
@patch("gradsflow.core.automodel.tune.run")
@patch("gradsflow.autotasks.engine.automodel.tune.run")
def test_hp_tune(
mock_tune,
):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
import pytest
import torch

from gradsflow.autotasks import AutoImageClassifier
from gradsflow.data.image import image_dataset_from_directory
from gradsflow.models.model import Model
from gradsflow.tasks import AutoImageClassifier

warnings.filterwarnings("ignore")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

from unittest.mock import MagicMock

from gradsflow.tasks import AutoSummarization
from gradsflow.autotasks import AutoSummarization


def test_build_model():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

from unittest.mock import MagicMock

from gradsflow.tasks import AutoTextClassifier
from gradsflow.autotasks import AutoTextClassifier


def test_build_model():
Expand Down
1 change: 0 additions & 1 deletion tests/data/test_ray_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
# limitations under the License.
from pathlib import Path

import numpy as np
from PIL import Image

from gradsflow.data.ray_dataset import RayDataset, RayImageFolder
Expand Down

0 comments on commit 3fe670e

Please sign in to comment.