Skip to content

Commit

Permalink
💥 Rename model to models
Browse files Browse the repository at this point in the history
  • Loading branch information
Asthestarsfalll committed Nov 28, 2024
1 parent f50eccd commit bb734bd
Show file tree
Hide file tree
Showing 13 changed files with 16 additions and 17 deletions.
2 changes: 1 addition & 1 deletion docs/blog/2024-2-29-config-system-in-deeplearning.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ model = modules.Model

ExCore同样支持python形式的配置文件,与detectron2基本一致,不过实例化时只需调用`__call__`方法即可,如下:
```python
from excore.config.model import ModuleNode
from excore.config.models import ModuleNode
from xxx import Module
cfg = ModuleNode(Module) << dict(arg1=1, arg2=2)
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/config/config_extention.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ It will generate a python file named `types`:

```python
from typing import Union, Any
from excore.config.model import ModuleNode, ModuleWrapper
from excore.config.models import ModuleNode, ModuleWrapper

class ModuleType:
Model: Union[ModuleNode, ModuleWrapper]
Expand Down
4 changes: 2 additions & 2 deletions docs/docs/config/node.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ title: Module nodes
In fact, those nodes is called `LazyCall` in `detectron2`. Although the whole system is designed for toml file, but they still can be used in pure python configurations.
For instance:
```python
from excore.config.model import ModuleNode
from excore.config.models import ModuleNode
from xxx import Module

cfg = ModuleNode(Module) << dict(arg1=1, arg2=2)
Expand Down Expand Up @@ -54,7 +54,7 @@ Wrap the chained invocation of a node, for example:

If we want to implement `ResNet().blocks.conv()`, we can use `ChainedInvocationWrapper`
```python
from excore.config.model import ModuleNode, ChainedInvocationWrapper
from excore.config.models import ModuleNode, ChainedInvocationWrapper
from xxx import ResNet

ChainedInvocationWrapper(ModuleNode(ResNet), ["blocks", "conv()"])
Expand Down
2 changes: 1 addition & 1 deletion excore/cli/_extention.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def _generate_typehints(
logger.info(f"Generating module type hints in {target_file}.")
with open(target_file, "w", encoding="UTF-8") as f:
f.write(f"from typing import Union{', Any' if config else ''}\n")
f.write("from excore.config.model import ModuleNode, ModuleWrapper\n\n")
f.write("from excore.config.models import ModuleNode, ModuleWrapper\n\n")
f.write(f"class {class_name}:\n")
for i in workspace.primary_fields:
f.write(f" {i}: Union[ModuleNode, ModuleWrapper]\n")
Expand Down
2 changes: 1 addition & 1 deletion excore/config/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from .action import DictAction
from .config import build_all, load, load_config
from .model import (
from .models import (
ChainedInvocationWrapper,
ClassNode,
InterNode,
Expand Down
2 changes: 1 addition & 1 deletion excore/config/_json_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from ..engine.hook import ConfigArgumentHook
from ..engine.logging import logger
from ..engine.registry import Registry, load_registries
from .model import _str_to_target
from .models import _str_to_target

if sys.version_info >= (3, 10, 0):
from types import NoneType, UnionType # type: ignore
Expand Down
2 changes: 1 addition & 1 deletion excore/config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from ..engine.logging import logger
from ..engine.registry import load_registries
from .lazy_config import LazyConfig
from .model import ModuleWrapper
from .models import ModuleWrapper
from .parse import ConfigDict

__all__ = ["load", "build_all", "load_config"]
Expand Down
2 changes: 1 addition & 1 deletion excore/config/lazy_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from ..engine.hook import ConfigHookManager, Hook
from ..engine.logging import logger
from ..engine.registry import Registry
from .model import ConfigHookNode, InterNode, ModuleWrapper
from .models import ConfigHookNode, InterNode, ModuleWrapper
from .parse import ConfigDict


Expand Down
6 changes: 3 additions & 3 deletions excore/config/model.py → excore/config/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
NoCallSkipFlag = Self
ConfigHookSkipFlag = Type[None]

SpecialFlag = Literal["@", "!", "$", "&", ""]
SpecialFlag = Literal["@", "!", "$", "&", "*", ""]


__all__ = ["silent"]
Expand All @@ -34,6 +34,7 @@
INTER_FLAG: Literal["!"] = "!"
CLASS_FLAG: Literal["$"] = "$"
REFER_FLAG: Literal["&"] = "&"
DETAI_FLAG: Literal["*"] = "*"
OTHER_FLAG: Literal[""] = ""

LOG_BUILD_MESSAGE = True
Expand All @@ -59,7 +60,7 @@ def _is_special(k: str) -> tuple[str, SpecialFlag]:
Returns:
Tuple[str, str]: A tuple containing the modified string and the special character.
"""
pattern = re.compile(r"^([@!$&])(.*)$")
pattern = re.compile(r"^([@!$&*])(.*)$")
match = pattern.match(k)
if match:
return match.group(2), match.group(1) # type: ignore
Expand Down Expand Up @@ -169,7 +170,6 @@ def from_node(cls, _other: ModuleNode) -> ModuleNode:

class InterNode(ModuleNode):
priority = 2
pass


class ConfigHookNode(ModuleNode):
Expand Down
4 changes: 2 additions & 2 deletions excore/config/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from .._exceptions import CoreConfigParseError, ImplicitModuleParseError
from .._misc import _create_table
from ..engine import Registry, logger
from .model import (
from .models import (
OTHER_FLAG,
REFER_FLAG,
ChainedInvocationWrapper,
Expand All @@ -23,7 +23,7 @@

from typing_extensions import Self

from .model import ConfigNode, NodeType, SpecialFlag
from .models import ConfigNode, NodeType, SpecialFlag


def _check_implicit_module(module: ModuleNode) -> None:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
ImplicitModuleParseError,
ModuleBuildError,
)
from excore.config.model import ModuleNode, ReusedNode
from excore.config.models import ModuleNode, ReusedNode
from excore.engine import logger


Expand Down
2 changes: 1 addition & 1 deletion tests/test_model.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest

from excore.config.model import ModuleNode
from excore.config.models import ModuleNode


def test_lshift():
Expand Down
1 change: 0 additions & 1 deletion tests/test_z_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ def test_primary():


def test_typehints():
# FIXME(typer): Argument
excute(
"excore generate-typehints temp_typing --class-name "
"TypedWrapper --info-class-name Info --config ./configs/launch/test_optim.toml"
Expand Down

0 comments on commit bb734bd

Please sign in to comment.