Skip to content

Commit

Permalink
Telemetry coverage extension (#3039)
Browse files Browse the repository at this point in the history
### Changes

- Extended coverage for telemetry.

### Reason for changes

- Telemetry update.

### Related tickets

- 154833

### Tests

- TBD

New _categories/events_ are introduced:
| Method  | Event category | Event name | Event label |
| ------------- | ------------- | ------------- | ------------- |
| _nncf.strip_ | nncf_tf,nncf_pt,nncf_pt_fx,nncf_onnx,nncf_ov |
_function_call_ | _nncf.strip_ |
| _nncf.data....generate_text_data_ | _nncf_ | _function_call_ |
_nncf.data.generate_text_data_ |
| _nncf.torch....wrap_model_ | nncf_pt | _function_call_ |
_nncf.torch.wrap_model_ |
| _nncf.torch....load_from_config_ | nncf_pt | _function_call_ |
_nncf.torch.load_from_config_ |
| _nncf.torch....get_config_ | nncf_pt | _function_call_ |
_nncf.torch.nncf_network.NNCFNetwork.get_config_ |
  • Loading branch information
nikita-malininn authored Jan 8, 2025
1 parent e14460d commit 801e5af
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 0 deletions.
4 changes: 4 additions & 0 deletions nncf/common/strip.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,15 @@
from nncf.common.utils.api_marker import api
from nncf.common.utils.backend import BackendType
from nncf.common.utils.backend import get_backend
from nncf.telemetry.decorator import tracked_function
from nncf.telemetry.events import MODEL_BASED_CATEGORY
from nncf.telemetry.extractors import FunctionCallTelemetryExtractor

TModel = TypeVar("TModel")


@api(canonical_alias="nncf.strip")
@tracked_function(category=MODEL_BASED_CATEGORY, extractors=[FunctionCallTelemetryExtractor("nncf.strip")])
def strip(model: TModel, do_copy: bool = True) -> TModel:
"""
Returns the model object with as much custom NNCF additions as possible removed
Expand Down
11 changes: 11 additions & 0 deletions nncf/data/generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,24 @@

import nncf
from nncf.common.logging.track_progress import track
from nncf.common.utils.api_marker import api
from nncf.telemetry import tracked_function
from nncf.telemetry.events import NNCF_CATEGORY
from nncf.telemetry.extractors import FunctionCallTelemetryExtractor

BASE_VOCAB_SIZE = 12000

TModel = TypeVar("TModel")
TTokenizer = TypeVar("TTokenizer")


@api(canonical_alias="nncf.data.generate_text_data")
@tracked_function(
category=NNCF_CATEGORY,
extractors=[
FunctionCallTelemetryExtractor("nncf.data.generate_text_data"),
],
)
def generate_text_data(
model: TModel, tokenizer: TTokenizer, seq_len: int = 32, dataset_size: int = 128, unique_tokens_lower_limit: int = 5
) -> List[str]:
Expand Down
3 changes: 3 additions & 0 deletions nncf/telemetry/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
from nncf.common.utils.backend import BackendType
from nncf.common.utils.backend import get_backend

# General categories
NNCF_CATEGORY = "nncf"

# Backend categories
NNCF_TF_CATEGORY = "nncf_tf"
NNCF_PT_CATEGORY = "nncf_pt"
Expand Down
9 changes: 9 additions & 0 deletions nncf/telemetry/extractors.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,12 @@ def extract(self, argvalue: SerializableData) -> CollectedEvent:
if isinstance(argvalue, bool):
argvalue = "enabled" if argvalue else "disabled"
return CollectedEvent(name=self._argname, data=argvalue)


class FunctionCallTelemetryExtractor(TelemetryExtractor):
def __init__(self, argvalue=None):
super().__init__()
self._argvalue = argvalue

def extract(self, _: Any):
return CollectedEvent(name="function_call", data=self._argvalue)
13 changes: 13 additions & 0 deletions nncf/torch/model_creation.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
from nncf.config.telemetry_extractors import CompressionStartedFromConfig
from nncf.telemetry import tracked_function
from nncf.telemetry.events import NNCF_PT_CATEGORY
from nncf.telemetry.extractors import FunctionCallTelemetryExtractor
from nncf.torch.algo_selector import PT_COMPRESSION_ALGORITHMS
from nncf.torch.algo_selector import NoCompressionAlgorithmBuilder
from nncf.torch.composite_compression import PTCompositeCompressionAlgorithmBuilder
Expand Down Expand Up @@ -324,6 +325,12 @@ def create_compression_algorithm_builder_from_algo_names(
return builder


@tracked_function(
NNCF_PT_CATEGORY,
[
FunctionCallTelemetryExtractor("nncf.torch.wrap_model"),
],
)
def wrap_model(
model: torch.nn.Module,
example_input: Any,
Expand Down Expand Up @@ -368,6 +375,12 @@ def is_wrapped_model(model: torch.nn.Module) -> bool:
return isinstance(model, NNCFNetwork)


@tracked_function(
NNCF_PT_CATEGORY,
[
FunctionCallTelemetryExtractor("nncf.torch.load_from_config"),
],
)
def load_from_config(model: torch.nn.Module, config: Dict[str, Any], example_input: Any) -> NNCFNetwork:
"""
Wraps given model to a NNCFNetwork and recovers additional modules from given NNCFNetwork config.
Expand Down
9 changes: 9 additions & 0 deletions nncf/torch/nncf_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@
from nncf.common.insertion_point_graph import PostHookInsertionPoint
from nncf.common.insertion_point_graph import PreHookInsertionPoint
from nncf.common.utils.debug import is_debug
from nncf.telemetry import tracked_function
from nncf.telemetry.events import NNCF_PT_CATEGORY
from nncf.telemetry.extractors import FunctionCallTelemetryExtractor
from nncf.torch.debug import CombinedDebugInterface
from nncf.torch.debug import debuggable_forward
from nncf.torch.dynamic_graph.context import PreHookId
Expand Down Expand Up @@ -781,6 +784,12 @@ def _collect_eval_op_scopes(self, model: nn.Module, dummy_forward_fn: Callable)
result.append(scope_in_model)
return result

@tracked_function(
NNCF_PT_CATEGORY,
[
FunctionCallTelemetryExtractor("nncf.torch.nncf_network.NNCFNetwork.get_config"),
],
)
def get_config(self) -> Dict[str, Any]:
"""
Returns serializable NNCFNetwork config which contains
Expand Down

0 comments on commit 801e5af

Please sign in to comment.