Skip to content

Commit 4af3dca

Browse files
horheynmbfineran
andauthored
[V2 Logger] Feature branch (#1516) (#1614)
* [V2 Logger] Feature branch (#1516) * logger feature beanch * [V2 Logger] utils for import (#1536) * utils for import * clean up + tests * [V2 Logger] registry for default func/class (#1539) * registry for default func/class * prometheus logger * clean up * clean up * remove ListLogger import, moved to tests * add base logger for type checking * exmaple * [V2 Logger] Filters (#1540) * filters * cleaner logic * fix bug -- if config has duplicated tag.func with different freq * delete config test * move unravel_value_as_generator to pattern.py * tests * doc string * exact match * async submitter (#1538) * manager (#1541) * [V2 Loggers] logger manager patch (#1560) * manager * doc string * [V2 Loggers] config file (#1533) * config file * test * comments * comments * pipeline tests (#1553) * [V2 Logger] root logger (#1542) * root logger * only get func's with respect to the tag * fix bug for duplicated tag.log_type * clena up * doc strings: * loosen up rules for capture * [V2 Logger] factory (#1537) * factory * docstring * [V2 Logger] logger middleware (#1543) * logger middleware * yield individual eleeents in a list * comments * edit state * polish, passes tests * pass middleware * edit condition to add logger to inference state * set default logger manager * delete og prometheus logger test * fix in test_basic_logger * move loggers to legacy and pass tests, circular imports * move tests/deepsparse/loggers to tests/deepsparse/legacy/loggers and pass tests * move loggers_v2 to logger for src and tests, pass logger tests * fix tests and rename legacy logger tests to _legacy_ * pass tests, wait for async logs to complete' * doc string typo and change default to re:.* * fix frequency test bug on text gen * wait for async loggers to finish before counting * get rid of capture, inconsistent number of fields per log calls cause error * fix src. reference (#1607) --------- Co-authored-by: Benjamin Fineran <[email protected]>
1 parent 9480c5f commit 4af3dca

File tree

102 files changed

+3274
-387
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

102 files changed

+3274
-387
lines changed

Diff for: src/deepsparse/__init__.py

-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
from .pipeline_config import *
3535
from .tasks import *
3636
from .pipeline import *
37-
from .loggers import *
3837
from .version import __version__, is_release
3938
from .analytics import deepsparse_analytics as _analytics
4039
from .subgraph_execute import *

Diff for: src/deepsparse/legacy/base_pipeline.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@
1919
from pydantic import BaseModel
2020

2121
from deepsparse import Context
22+
from deepsparse.legacy.loggers.base_logger import BaseLogger
23+
from deepsparse.legacy.loggers.build_logger import logger_from_config
24+
from deepsparse.legacy.loggers.constants import validate_identifier
2225
from deepsparse.legacy.tasks import SupportedTasks, dynamic_import_task
23-
from deepsparse.loggers.base_logger import BaseLogger
24-
from deepsparse.loggers.build_logger import logger_from_config
25-
from deepsparse.loggers.constants import validate_identifier
2626

2727

2828
__all__ = [

Diff for: src/deepsparse/legacy/loggers/__init__.py

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Copyright (c) 2021 - present / Neuralmagic, Inc. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing,
10+
# software distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# flake8: noqa
16+
# isort: skip_file
17+
18+
# base modules
19+
from .base_logger import *
20+
from .constants import *
21+
22+
23+
# logger implementations
24+
from .async_logger import *
25+
from .function_logger import *
26+
from .multi_logger import *
27+
from .prometheus_logger import *
28+
from .python_logger import *
29+
30+
# functions for creating complex loggers
31+
from .build_logger import *

Diff for: src/deepsparse/loggers/async_logger.py renamed to src/deepsparse/legacy/loggers/async_logger.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
from concurrent.futures import Executor, ThreadPoolExecutor
2222
from typing import Any
2323

24-
from deepsparse.loggers import BaseLogger, MetricCategories
24+
from deepsparse.legacy.loggers import BaseLogger, MetricCategories
2525

2626

2727
__all__ = ["AsyncLogger"]
File renamed without changes.

Diff for: src/deepsparse/loggers/build_logger.py renamed to src/deepsparse/legacy/loggers/build_logger.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
import yaml
2727

28-
from deepsparse.loggers import (
28+
from deepsparse.legacy.loggers import (
2929
FROM_PREDEFINED,
3030
AsyncLogger,
3131
BaseLogger,
@@ -34,14 +34,14 @@
3434
PrometheusLogger,
3535
PythonLogger,
3636
)
37-
from deepsparse.loggers.config import (
37+
from deepsparse.legacy.loggers.config import (
3838
MetricFunctionConfig,
3939
PipelineLoggingConfig,
4040
SystemLoggingConfig,
4141
SystemLoggingGroup,
4242
)
43-
from deepsparse.loggers.helpers import get_function_and_function_name
44-
from deepsparse.loggers.metric_functions.registry import DATA_LOGGING_REGISTRY
43+
from deepsparse.legacy.loggers.helpers import get_function_and_function_name
44+
from deepsparse.legacy.loggers.metric_functions.registry import DATA_LOGGING_REGISTRY
4545

4646

4747
__all__ = [

Diff for: src/deepsparse/legacy/loggers/config.py

+140
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
# Copyright (c) 2021 - present / Neuralmagic, Inc. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing,
10+
# software distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
from typing import Any, Dict, List, Optional
16+
17+
from pydantic import BaseModel, Field, validator
18+
19+
20+
"""
21+
Implements schemas for the configs pertaining to logging
22+
"""
23+
24+
__all__ = [
25+
"MetricFunctionConfig",
26+
"SystemLoggingGroup",
27+
"SystemLoggingConfig",
28+
"PipelineLoggingConfig",
29+
]
30+
31+
32+
class MetricFunctionConfig(BaseModel):
33+
"""
34+
Holds logging configuration for a metric function
35+
"""
36+
37+
func: str = Field(
38+
description="The name that specifies the metric function to be applied. "
39+
"It can be: "
40+
"1) a built-in function name "
41+
"2) a dynamic import function of the form "
42+
"'<path_to_the_python_script>:<function_name>' "
43+
"3) a framework function (e.g. np.mean or torch.mean)"
44+
)
45+
46+
frequency: int = Field(
47+
description="Specifies how often the function should be applied"
48+
"(measured in numbers of inference calls).",
49+
default=1,
50+
)
51+
52+
target_loggers: List[str] = Field(
53+
default=[],
54+
description="Overrides the global logger configuration."
55+
"If not an empty list, this configuration stops logging data "
56+
"to globally specified loggers, and will only use "
57+
"the subset of loggers (specified here by a list of their names).",
58+
)
59+
60+
@validator("frequency")
61+
def non_zero_frequency(cls, frequency: int) -> int:
62+
if frequency <= 0:
63+
raise ValueError(
64+
f"Passed frequency: {frequency}, but "
65+
"frequency must be a positive integer greater equal 1"
66+
)
67+
return frequency
68+
69+
70+
class SystemLoggingGroup(BaseModel):
71+
"""
72+
Holds the configuration for a single system logging group.
73+
"""
74+
75+
enable: bool = Field(
76+
default=False,
77+
description="Whether to enable the system logging group. Defaults to False",
78+
)
79+
80+
target_loggers: List[str] = Field(
81+
default=[],
82+
description="The list of target loggers to log to. "
83+
"If None, logs to all the available loggers",
84+
)
85+
86+
87+
class SystemLoggingConfig(BaseModel):
88+
# Global Logging Config
89+
enable: bool = Field(
90+
default=True, description="Whether to enable system logging. Defaults to True"
91+
)
92+
93+
94+
class PipelineSystemLoggingConfig(SystemLoggingConfig):
95+
"""
96+
Holds the configuration for the system logging
97+
in the context of a single pipeline
98+
"""
99+
100+
# Pipeline System Logging Groups
101+
inference_details: SystemLoggingGroup = Field(
102+
default=SystemLoggingGroup(enable=False),
103+
description="The configuration group for the inference details "
104+
"logging group. By default this group is disabled.",
105+
)
106+
prediction_latency: SystemLoggingGroup = Field(
107+
default=SystemLoggingGroup(enable=True),
108+
description="The configuration group for the prediction latency "
109+
"logging group. By default this group is enabled.",
110+
)
111+
112+
113+
class PipelineLoggingConfig(BaseModel):
114+
"""
115+
Holds the complete configuration for the logging
116+
in the context of a single pipeline
117+
"""
118+
119+
loggers: Dict[str, Optional[Dict[str, Any]]] = Field(
120+
default={},
121+
description=(
122+
"Optional dictionary of logger integration names to initialization kwargs."
123+
"Set to {} for no loggers. Default is {}."
124+
),
125+
)
126+
127+
system_logging: PipelineSystemLoggingConfig = Field(
128+
default=PipelineSystemLoggingConfig(),
129+
description="A model that holds the system logging configuration. "
130+
"If not specified explicitly in the yaml config, the "
131+
"default SystemLoggingConfig model is used.",
132+
)
133+
134+
data_logging: Optional[Dict[str, List[MetricFunctionConfig]]] = Field(
135+
default=None,
136+
description="Specifies the rules for the data logging. "
137+
"It relates a key (name of the logging target) "
138+
"to a list of metric functions that are to be applied"
139+
"to this target prior to logging.",
140+
)

Diff for: src/deepsparse/legacy/loggers/constants.py

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
"""
2+
Holds logging-related objects with constant values
3+
"""
4+
# Copyright (c) 2021 - present / Neuralmagic, Inc. All Rights Reserved.
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing,
13+
# software distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
18+
from dataclasses import dataclass
19+
from enum import Enum
20+
21+
22+
__all__ = [
23+
"MetricCategories",
24+
"validate_identifier",
25+
"SystemGroups",
26+
"FROM_PREDEFINED",
27+
]
28+
29+
UNSUPPORTED_IDENTIFIER_CHARS = {".", "[", "]"}
30+
FROM_PREDEFINED = "predefined"
31+
32+
33+
class MetricCategories(Enum):
34+
"""
35+
Metric Taxonomy [for reference]
36+
CATEGORY - category of metric (System/Data)
37+
GROUP - logical group of metrics
38+
METRIC - individual metric
39+
"""
40+
41+
# Categories
42+
SYSTEM = "system"
43+
DATA = "data"
44+
45+
46+
@dataclass(frozen=True)
47+
class SystemGroups:
48+
# Pipeline System Groups
49+
INFERENCE_DETAILS: str = "inference_details"
50+
PREDICTION_LATENCY: str = "prediction_latency"
51+
# Server System Groups
52+
REQUEST_DETAILS: str = "request_details"
53+
RESOURCE_UTILIZATION: str = "resource_utilization"
54+
55+
56+
def validate_identifier(identifier: str):
57+
"""
58+
Makes sure that the identifier does not contain any
59+
of the characters that would introduce ambiguity
60+
when parsing the identifier
61+
62+
:param identifier: a string that is used
63+
to identify a log
64+
"""
65+
for char in UNSUPPORTED_IDENTIFIER_CHARS:
66+
if char in identifier:
67+
raise ValueError(
68+
f"Logging identifier: {identifier} "
69+
f"contains unsupported character {char}"
70+
)

Diff for: src/deepsparse/loggers/function_logger.py renamed to src/deepsparse/legacy/loggers/function_logger.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,12 @@
1818
import textwrap
1919
from typing import Any, Callable
2020

21-
from deepsparse.loggers import BaseLogger, MetricCategories
22-
from deepsparse.loggers.helpers import NO_MATCH, finalize_identifier, match_and_extract
21+
from deepsparse.legacy.loggers import BaseLogger, MetricCategories
22+
from deepsparse.legacy.loggers.helpers import (
23+
NO_MATCH,
24+
finalize_identifier,
25+
match_and_extract,
26+
)
2327

2428

2529
__all__ = ["FunctionLogger"]

Diff for: src/deepsparse/loggers/helpers.py renamed to src/deepsparse/legacy/loggers/helpers.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@
2424

2525
import numpy
2626

27-
import deepsparse.loggers.metric_functions as built_ins
28-
from deepsparse.loggers import MetricCategories
29-
from deepsparse.loggers.metric_functions.utils import BatchResult
27+
import deepsparse.legacy.loggers.metric_functions as built_ins
28+
from deepsparse.legacy.loggers import MetricCategories
29+
from deepsparse.legacy.loggers.metric_functions.utils import BatchResult
3030

3131

3232
__all__ = [

Diff for: src/deepsparse/loggers/metric_functions/built_ins.py renamed to src/deepsparse/legacy/loggers/metric_functions/built_ins.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616
"""
1717
from typing import Any, List, Union
1818

19-
from deepsparse.loggers.metric_functions.registry import (
19+
from deepsparse.legacy.loggers.metric_functions.registry import (
2020
register as register_metric_function,
2121
)
22-
from deepsparse.loggers.metric_functions.utils import BatchResult
22+
from deepsparse.legacy.loggers.metric_functions.utils import BatchResult
2323

2424

2525
__all__ = ["identity", "predicted_classes", "predicted_top_score"]

Diff for: src/deepsparse/loggers/metric_functions/computer_vision/built_ins.py renamed to src/deepsparse/legacy/loggers/metric_functions/computer_vision/built_ins.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@
1919

2020
import numpy
2121

22-
from deepsparse.loggers.metric_functions.registry import (
22+
from deepsparse.legacy.loggers.metric_functions.registry import (
2323
register as register_metric_function,
2424
)
25-
from deepsparse.loggers.metric_functions.utils import BatchResult
25+
from deepsparse.legacy.loggers.metric_functions.utils import BatchResult
2626

2727

2828
__all__ = [

Diff for: src/deepsparse/loggers/metric_functions/helpers/config_generation.py renamed to src/deepsparse/legacy/loggers/metric_functions/helpers/config_generation.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@
2525

2626
import yaml
2727

28-
from deepsparse.loggers.build_logger import parse_out_predefined_function_groups
29-
from deepsparse.loggers.config import MetricFunctionConfig
30-
from deepsparse.loggers.metric_functions.registry import DATA_LOGGING_REGISTRY
28+
from deepsparse.legacy.loggers.build_logger import parse_out_predefined_function_groups
29+
from deepsparse.legacy.loggers.config import MetricFunctionConfig
30+
from deepsparse.legacy.loggers.metric_functions.registry import DATA_LOGGING_REGISTRY
3131

3232

3333
_WHITESPACE = " "

Diff for: src/deepsparse/loggers/metric_functions/natural_language_processing/built_ins.py renamed to src/deepsparse/legacy/loggers/metric_functions/natural_language_processing/built_ins.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616
"""
1717
from typing import List, Union
1818

19-
from deepsparse.loggers.metric_functions.registry import (
19+
from deepsparse.legacy.loggers.metric_functions.registry import (
2020
register as register_metric_function,
2121
)
22-
from deepsparse.loggers.metric_functions.utils import BatchResult
22+
from deepsparse.legacy.loggers.metric_functions.utils import BatchResult
2323

2424

2525
__all__ = ["string_length", "percent_unknown_tokens"]

Diff for: src/deepsparse/loggers/metric_functions/natural_language_processing/question_answering/built_ins.py renamed to src/deepsparse/legacy/loggers/metric_functions/natural_language_processing/question_answering/built_ins.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
Set of functions for logging metrics from the question answering pipeline
1616
"""
1717

18-
from deepsparse.loggers.metric_functions.natural_language_processing import (
18+
from deepsparse.legacy.loggers.metric_functions.natural_language_processing import (
1919
string_length,
2020
)
21-
from deepsparse.loggers.metric_functions.registry import (
21+
from deepsparse.legacy.loggers.metric_functions.registry import (
2222
register as register_metric_function,
2323
)
2424

0 commit comments

Comments
 (0)