-
Notifications
You must be signed in to change notification settings - Fork 54
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
Make shortcuts for imports #535
Comments
Hello! I'm interested in contributing to this issue. Is it still open? Could you confirm if the goal here is to simplify imports and enhance readability by reducing import depth across all affected files? |
Hey, @mimi030 That's correct. Ideally, I want to have no more than 2 levels in our imports. For example, I think, you can start with losses, models and miners. I would'n touch validation part much at the moment because we are expecting big updates there. |
Thanks for clarifying the scope, @AlekseySh ! I'll start by simplifying import paths within the 'losses,' 'models,' and 'miners' modules to ensure they don't exceed two levels. For example, I'll refactor import statements like this: # Example from oml/models/vit_unicom/extractor.py
# Before refactoring
from oml.interfaces.models import IExtractor
from oml.models.utils import (
remove_criterion_in_state_dict,
remove_prefix_from_state_dict,
)
from oml.models.vit_unicom.external import vision_transformer
from oml.models.vit_unicom.external.model import load # type: ignore
from oml.utils.misc_torch import normalise
# After refactoring
from oml.interfaces import IExtractor
from oml.models import (
remove_criterion_in_state_dict,
remove_prefix_from_state_dict,
vision_transformer,
load, # type: ignore
)
from oml.utils import normalise Could you also clarify which components are included in the 'validation part' you mentioned? Is it related to the extractor_training_pipeline and extractor_validation_pipeline, or the validation steps outlined in the documentation? Thanks for your help! I'll also update relevant examples in the documentation to reflect these changes. |
Your example looks great! By validation part I mean postprocessors, metrics and so on. So, that is why I suggest to start with losses, miners, samplers, and models. You can simplify their imports everywhere. |
Thanks for your guidance! I've started simplifying imports across all files in losses, models, miners, and samplers modules. However, a couple of questions popped up:
# Example from 'Training' from Examples in 'Feature Extraction'
# Original import statements:
import torch
from tqdm import tqdm
from oml.datasets.base import DatasetWithLabels
from oml.losses.triplet import TripletLossWithMiner
from oml.miners.inbatch_all_tri import AllTripletsMiner
from oml.models import ViTExtractor
from oml.samplers.balance import BalanceSampler
from oml.utils.download_mock_dataset import download_mock_dataset
# Revised import statements:
import torch
from tqdm import tqdm
from oml.datasets.base import DatasetWithLabels
from oml.losses import TripletLossWithMiner
from oml.miners import AllTripletsMiner
from oml.models import ViTExtractor
from oml.samplers import BalanceSampler
from oml.utils.download_mock_dataset import download_mock_dataset |
Hi!
|
Anyway, it's hard to to predict all the possible combinations in advance. So, you can create a relatively small PR with only criterions optimization (for example), where we can discuss corner cases which can arise. |
Thanks for the suggestion! I've submitted a pull request with initial changes focusing on import simplification. Feel free to review it when you have time. One note: the import simplification led to some test errors. Also, I needed to install If you have other adjustments or optimizations to discuss, I'm ready to work on those. Thanks! |
@mimi030 we should not include this to the package to make the original package lighter. But I think it would be good if you add this information to the contribution guide: https://github.com/OML-Team/open-metric-learning/blob/main/CONTRIBUTING.md . You can mention that contributor may need to install one of:
|
Hey @AlekseySh, I made another pull request, could you review this one? |
from oml.datasets.base import X
->from oml.datasets import X
So, make all the functions and classes accessible with no more than two-level imports
The text was updated successfully, but these errors were encountered: