Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RFC] Engine Refactor Proposal | Alternative 2 #3760

Draft
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

ashwinvaidya17
Copy link
Contributor

@ashwinvaidya17 ashwinvaidya17 commented Jul 23, 2024

Motivation

Refer to #3752 for the motivation

This PR proposes an alternative design. It also includes one solution to register heterogeneous models to the CLI (there might be better approaches).

def test_engine_anomaly():
    model = Padim()
    engine = Engine(model)
    datamodule = MVTec(root="./datasets/MVTec")
    engine.train(datamodule)
    assert isinstance(engine, AnomalyEngine)


def test_engine_classification():
    datamodule = OTXDataModule(
        task=OTXTaskType.MULTI_CLASS_CLS,
        ...
    )
    model = MobileNetV3ForMulticlassCls(
        label_info=datamodule.label_info,
    )
    engine = Engine(model)
    engine.train(datamodule, max_epochs=1, deterministic=False, val_check_interval=0.5)
    assert isinstance(engine, LightningEngine)


def test_engine_ultralytics():
    model = YOLO("yolov8n.pt")
    engine = Engine(model)
    dataset = ClassificationDataset(root="./datasets/hazelnut_toy", args=DEFAULT_CFG)
    dataloader = DataLoader(dataset, batch_size=32, shuffle=True)
    engine.train(datamodule=dataloader)
    assert isinstance(engine, UltralyticsEngine)

Signed-off-by: Ashwin Vaidya <ashwinnitinvaidya@gmail.com>
Signed-off-by: Ashwin Vaidya <ashwinnitinvaidya@gmail.com>
"""Mock autoconfigurator for the engine."""

def __init__(self, model: nn.Module | None = None, data_root: Path | None = None, task: str | None = None):
self._engine = self._configure_engine(model) # ideally we want to pass the data_root and task as well
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently, the role of auto-configuration is to check for task, data, and model inputs, regardless of the engine, and provide default settings for anything the user hasn't entered. Is there any reason to configure the engine internally? If it's just for the backend, it would be nice to have a different way to configure the default for each backend rather than configuring the engine directly. What do you think?

**kwargs,
) -> BaseEngine:
"""This takes in all the parameters that are currently passed to the OTX Engine's `__init__` method."""
autoconfigurator = AutoConfigurator(model, data_root=data_root, **kwargs)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Engine -> AutoConfigurator -> Engine : I think their relationship with each other is strange.

ANNOTATIONS = Any


class BaseEngine(ABC):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As we talked about, the arguments in BaseEngine will be the same as those in the current otx Engine, only the Type will be made more general as needed, right?

pass

@abstractmethod
def train(self, model: nn.Module, **kwargs) -> METRICS:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's still a model here, which I think might be confusing for people looking at this PR.

@sovrasov sovrasov removed the OTX 2.0 label Oct 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants