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

[V2 Logger] Feature branch #1516

Merged
merged 37 commits into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
333481c
logger feature beanch
horheynm Jan 8, 2024
17b141f
Merge branch 'main' into v2/logger
horheynm Jan 8, 2024
361630b
Merge branch 'main' into v2/logger
horheynm Jan 17, 2024
22069aa
[V2 Logger] utils for import (#1536)
horheynm Jan 22, 2024
4eeefe5
[V2 Logger] registry for default func/class (#1539)
horheynm Jan 22, 2024
dff765b
[V2 Logger] Filters (#1540)
horheynm Jan 22, 2024
08f8a1d
async submitter (#1538)
horheynm Jan 22, 2024
0d47540
manager (#1541)
horheynm Jan 22, 2024
a529362
Merge branch 'main' into v2/logger
horheynm Jan 23, 2024
f8267ca
[V2 Loggers] logger manager patch (#1560)
horheynm Jan 24, 2024
b963ebc
[V2 Loggers] config file (#1533)
horheynm Jan 24, 2024
5715bcf
pipeline tests (#1553)
horheynm Jan 24, 2024
9ddeb0c
[V2 Logger] root logger (#1542)
horheynm Jan 24, 2024
e2e116e
[V2 Logger] factory (#1537)
horheynm Jan 24, 2024
eeed9f7
[V2 Logger] logger middleware (#1543)
horheynm Jan 24, 2024
22b7c9c
Merge branch 'main' into v2/logger
horheynm Jan 24, 2024
d19b819
polish, passes tests
horheynm Jan 24, 2024
586d515
Merge branch 'main' into v2/logger
horheynm Jan 24, 2024
50868f8
pass middleware
horheynm Jan 24, 2024
19af542
edit condition to add logger to inference state
horheynm Jan 24, 2024
1a9ff43
set default logger manager
horheynm Jan 24, 2024
e4f2ed3
delete og prometheus logger test
horheynm Jan 25, 2024
30d73e1
fix in test_basic_logger
horheynm Jan 25, 2024
0c8111c
move loggers to legacy and pass tests, circular imports
horheynm Jan 25, 2024
82c41fc
move tests/deepsparse/loggers to tests/deepsparse/legacy/loggers and …
horheynm Jan 25, 2024
66c0939
move loggers_v2 to logger for src and tests, pass logger tests
horheynm Jan 25, 2024
cc2f6e9
fix tests and rename legacy logger tests to _legacy_
horheynm Jan 25, 2024
6591e07
pass tests, wait for async logs to complete'
horheynm Jan 25, 2024
35e8552
Merge branch 'main' into v2/logger
horheynm Jan 25, 2024
58e74e6
doc string typo and change default to re:.*
horheynm Jan 26, 2024
6d27eaa
fix frequency test bug on text gen
horheynm Jan 29, 2024
b0b0a84
Merge branch 'main' into v2/logger
horheynm Jan 29, 2024
2979105
wait for async loggers to finish before counting
horheynm Jan 29, 2024
c8d51eb
Merge branch 'main' into v2/logger
horheynm Jan 29, 2024
7a60bc0
Merge branch 'v2/logger' of github.com:neuralmagic/deepsparse into v2…
horheynm Jan 29, 2024
067a38a
get rid of capture, inconsistent number of fields per log calls cause…
horheynm Jan 29, 2024
590251f
Merge branch 'main' into v2/logger
horheynm Feb 15, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/deepsparse/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
from .pipeline_config import *
from .tasks import *
from .pipeline import *
from .loggers import *
from .version import __version__, is_release
from .analytics import deepsparse_analytics as _analytics
from .subgraph_execute import *
Expand Down
6 changes: 3 additions & 3 deletions src/deepsparse/legacy/base_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
from pydantic import BaseModel

from deepsparse import Context
from deepsparse.legacy.loggers.base_logger import BaseLogger
from deepsparse.legacy.loggers.build_logger import logger_from_config
from deepsparse.legacy.loggers.constants import validate_identifier
from deepsparse.legacy.tasks import SupportedTasks, dynamic_import_task
from deepsparse.loggers.base_logger import BaseLogger
from deepsparse.loggers.build_logger import logger_from_config
from deepsparse.loggers.constants import validate_identifier


__all__ = [
Expand Down
31 changes: 31 additions & 0 deletions src/deepsparse/legacy/loggers/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Copyright (c) 2021 - present / Neuralmagic, Inc. 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.

# flake8: noqa
# isort: skip_file

# base modules
from .base_logger import *
from .constants import *


# logger implementations
from .async_logger import *
from .function_logger import *
from .multi_logger import *
from .prometheus_logger import *
from .python_logger import *

# functions for creating complex loggers
from .build_logger import *
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from concurrent.futures import Executor, ThreadPoolExecutor
from typing import Any

from deepsparse.loggers import BaseLogger, MetricCategories
from deepsparse.legacy.loggers import BaseLogger, MetricCategories


__all__ = ["AsyncLogger"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

import yaml

from deepsparse.loggers import (
from deepsparse.legacy.loggers import (
FROM_PREDEFINED,
AsyncLogger,
BaseLogger,
Expand All @@ -34,14 +34,14 @@
PrometheusLogger,
PythonLogger,
)
from deepsparse.loggers.config import (
from deepsparse.legacy.loggers.config import (
MetricFunctionConfig,
PipelineLoggingConfig,
SystemLoggingConfig,
SystemLoggingGroup,
)
from deepsparse.loggers.helpers import get_function_and_function_name
from deepsparse.loggers.metric_functions.registry import DATA_LOGGING_REGISTRY
from deepsparse.legacy.loggers.helpers import get_function_and_function_name
from deepsparse.legacy.loggers.metric_functions.registry import DATA_LOGGING_REGISTRY


__all__ = [
Expand Down
140 changes: 140 additions & 0 deletions src/deepsparse/legacy/loggers/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
# Copyright (c) 2021 - present / Neuralmagic, Inc. 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.

from typing import Any, Dict, List, Optional

from pydantic import BaseModel, Field, validator


"""
Implements schemas for the configs pertaining to logging
"""

__all__ = [
"MetricFunctionConfig",
"SystemLoggingGroup",
"SystemLoggingConfig",
"PipelineLoggingConfig",
]


class MetricFunctionConfig(BaseModel):
"""
Holds logging configuration for a metric function
"""

func: str = Field(
description="The name that specifies the metric function to be applied. "
"It can be: "
"1) a built-in function name "
"2) a dynamic import function of the form "
"'<path_to_the_python_script>:<function_name>' "
"3) a framework function (e.g. np.mean or torch.mean)"
)

frequency: int = Field(
description="Specifies how often the function should be applied"
"(measured in numbers of inference calls).",
default=1,
)

target_loggers: List[str] = Field(
default=[],
description="Overrides the global logger configuration."
"If not an empty list, this configuration stops logging data "
"to globally specified loggers, and will only use "
"the subset of loggers (specified here by a list of their names).",
)

@validator("frequency")
def non_zero_frequency(cls, frequency: int) -> int:
if frequency <= 0:
raise ValueError(
f"Passed frequency: {frequency}, but "
"frequency must be a positive integer greater equal 1"
)
return frequency


class SystemLoggingGroup(BaseModel):
"""
Holds the configuration for a single system logging group.
"""

enable: bool = Field(
default=False,
description="Whether to enable the system logging group. Defaults to False",
)

target_loggers: List[str] = Field(
default=[],
description="The list of target loggers to log to. "
"If None, logs to all the available loggers",
)


class SystemLoggingConfig(BaseModel):
# Global Logging Config
enable: bool = Field(
default=True, description="Whether to enable system logging. Defaults to True"
)


class PipelineSystemLoggingConfig(SystemLoggingConfig):
"""
Holds the configuration for the system logging
in the context of a single pipeline
"""

# Pipeline System Logging Groups
inference_details: SystemLoggingGroup = Field(
default=SystemLoggingGroup(enable=False),
description="The configuration group for the inference details "
"logging group. By default this group is disabled.",
)
prediction_latency: SystemLoggingGroup = Field(
default=SystemLoggingGroup(enable=True),
description="The configuration group for the prediction latency "
"logging group. By default this group is enabled.",
)


class PipelineLoggingConfig(BaseModel):
"""
Holds the complete configuration for the logging
in the context of a single pipeline
"""

loggers: Dict[str, Optional[Dict[str, Any]]] = Field(
default={},
description=(
"Optional dictionary of logger integration names to initialization kwargs."
"Set to {} for no loggers. Default is {}."
),
)

system_logging: PipelineSystemLoggingConfig = Field(
default=PipelineSystemLoggingConfig(),
description="A model that holds the system logging configuration. "
"If not specified explicitly in the yaml config, the "
"default SystemLoggingConfig model is used.",
)

data_logging: Optional[Dict[str, List[MetricFunctionConfig]]] = Field(
default=None,
description="Specifies the rules for the data logging. "
"It relates a key (name of the logging target) "
"to a list of metric functions that are to be applied"
"to this target prior to logging.",
)
70 changes: 70 additions & 0 deletions src/deepsparse/legacy/loggers/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
"""
Holds logging-related objects with constant values
"""
# Copyright (c) 2021 - present / Neuralmagic, Inc. 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.

from dataclasses import dataclass
from enum import Enum


__all__ = [
"MetricCategories",
"validate_identifier",
"SystemGroups",
"FROM_PREDEFINED",
]

UNSUPPORTED_IDENTIFIER_CHARS = {".", "[", "]"}
FROM_PREDEFINED = "predefined"


class MetricCategories(Enum):
"""
Metric Taxonomy [for reference]
CATEGORY - category of metric (System/Data)
GROUP - logical group of metrics
METRIC - individual metric
"""

# Categories
SYSTEM = "system"
DATA = "data"


@dataclass(frozen=True)
class SystemGroups:
# Pipeline System Groups
INFERENCE_DETAILS: str = "inference_details"
PREDICTION_LATENCY: str = "prediction_latency"
# Server System Groups
REQUEST_DETAILS: str = "request_details"
RESOURCE_UTILIZATION: str = "resource_utilization"


def validate_identifier(identifier: str):
"""
Makes sure that the identifier does not contain any
of the characters that would introduce ambiguity
when parsing the identifier

:param identifier: a string that is used
to identify a log
"""
for char in UNSUPPORTED_IDENTIFIER_CHARS:
if char in identifier:
raise ValueError(
f"Logging identifier: {identifier} "
f"contains unsupported character {char}"
)
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@
import textwrap
from typing import Any, Callable

from deepsparse.loggers import BaseLogger, MetricCategories
from deepsparse.loggers.helpers import NO_MATCH, finalize_identifier, match_and_extract
from deepsparse.legacy.loggers import BaseLogger, MetricCategories
from deepsparse.legacy.loggers.helpers import (
NO_MATCH,
finalize_identifier,
match_and_extract,
)


__all__ = ["FunctionLogger"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@

import numpy

import deepsparse.loggers.metric_functions as built_ins
from deepsparse.loggers import MetricCategories
from deepsparse.loggers.metric_functions.utils import BatchResult
import deepsparse.legacy.loggers.metric_functions as built_ins
from deepsparse.legacy.loggers import MetricCategories
from deepsparse.legacy.loggers.metric_functions.utils import BatchResult


__all__ = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
"""
from typing import Any, List, Union

from deepsparse.loggers.metric_functions.registry import (
from deepsparse.legacy.loggers.metric_functions.registry import (
register as register_metric_function,
)
from deepsparse.loggers.metric_functions.utils import BatchResult
from deepsparse.legacy.loggers.metric_functions.utils import BatchResult


__all__ = ["identity", "predicted_classes", "predicted_top_score"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@

import numpy

from deepsparse.loggers.metric_functions.registry import (
from deepsparse.legacy.loggers.metric_functions.registry import (
register as register_metric_function,
)
from deepsparse.loggers.metric_functions.utils import BatchResult
from deepsparse.legacy.loggers.metric_functions.utils import BatchResult


__all__ = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@

import yaml

from deepsparse.loggers.build_logger import parse_out_predefined_function_groups
from deepsparse.loggers.config import MetricFunctionConfig
from deepsparse.loggers.metric_functions.registry import DATA_LOGGING_REGISTRY
from deepsparse.legacy.loggers.build_logger import parse_out_predefined_function_groups
from deepsparse.legacy.loggers.config import MetricFunctionConfig
from deepsparse.legacy.loggers.metric_functions.registry import DATA_LOGGING_REGISTRY


_WHITESPACE = " "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
"""
from typing import List, Union

from deepsparse.loggers.metric_functions.registry import (
from deepsparse.legacy.loggers.metric_functions.registry import (
register as register_metric_function,
)
from deepsparse.loggers.metric_functions.utils import BatchResult
from deepsparse.legacy.loggers.metric_functions.utils import BatchResult


__all__ = ["string_length", "percent_unknown_tokens"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
Set of functions for logging metrics from the question answering pipeline
"""

from deepsparse.loggers.metric_functions.natural_language_processing import (
from deepsparse.legacy.loggers.metric_functions.natural_language_processing import (
string_length,
)
from deepsparse.loggers.metric_functions.registry import (
from deepsparse.legacy.loggers.metric_functions.registry import (
register as register_metric_function,
)

Expand Down
Loading
Loading