neuralmagic / deepsparse

Sparsity-aware deep learning inference runtime for CPUs
https://neuralmagic.com/deepsparse/
Other
2.99k stars 173 forks source link

[V2 Logger] Feature branch #1516

Closed horheynm closed 7 months ago

horheynm commented 9 months ago

PRs that compose the main functionality of this feature branch

Recommended order of review:

[MERGED] https://github.com/neuralmagic/deepsparse/pull/1533: config file -- Pydantic validation, and config file skeleton [MERGED] https://github.com/neuralmagic/deepsparse/pull/1536: utils (for import) -- config file may provide a name or path/to/file.py:ClassName, import helpers [MERGED] https://github.com/neuralmagic/deepsparse/pull/1539: registry for default func/class -- Default func, classnames [MERGED] https://github.com/neuralmagic/deepsparse/pull/1540: Filters -- we apply three filters (1) filter by tag (2) filer by frequency (3) only for metric loggers, filter by capture (keys, properties of an obj) [MERGED] https://github.com/neuralmagic/deepsparse/pull/1542: Root logger -- Responsible for organizing the parameters (freq, func, tag) into a data structure, so that it can apply the filtering rules in a simple fashion to log [MERGED] https://github.com/neuralmagic/deepsparse/pull/1537: Logger factory -- factory to get the root loggers and instantiate the leaf loggers [MERGED] https://github.com/neuralmagic/deepsparse/pull/1538: Async Submitter -- run something async [MERGED] https://github.com/neuralmagic/deepsparse/pull/1541: Logger Manager -- responsible for instantiating and assigning logging jobs to the root loggers [MERGED] https://github.com/neuralmagic/deepsparse/pull/1543: Logger middleware -- responsible to log output using middleware [MERGED] https://github.com/neuralmagic/deepsparse/pull/1553 -- tests with pipeline

https://github.com/neuralmagic/deepsparse/pull/1516: Current feature branch

Changes

Screenshot 2024-01-19 at 1 40 27 PM

Description

Given a yaml config file that describes the logger, tag, function to apply, rate to log (frequency) for three log_type entrypoints: system, performance, metrics, create .log(log_type, value, tag).

What happens under the hood

Instantiation

  1. Parse the config into pydantic, check if in appropriate format
  2. Build and create leaf loggers (singleton), root loggers, frequency state (with respect to log_type, wrt tag wrt func), and instantiate Async callable. Note that the root logger can share the same leaf logger, bc they are singletons.

Basic dependencies:

calling .log(...)

  1. Send all kwargs to AsyncExecutor to execute downstream code async
  2. Select which log_type RootLoggers to use (that root logger already have loggers and frequencies set up)
  3. Tag filter. Check if the given tag from kwargs is valid with the tag in the config file (tag in the config file can be a regex). If matches with any of the tag, then proceed
  4. Frequency filter. Check if the current log call is valid via frequency filter (filter wrt tag, log_type, func, one counter for the combination of the three.. AKA {log_type.tag.func: counter}) ***
  5. compute func(value) and proceed, reuse the func(value) for any of the next frequency counter matches
  6. For each leaf logger, log it out

*** Example with the filters from config

metric:
  "a":
    - func: max
      freq: 2
      uses:
        - prometheus
        - default

  "b":
    - func: max
      freq: 3
      uses:
        - prometheus
        - python
log(tag=a, value=1, log_type="system") # no log to any of "a"
log(tag=a, value=1, log_type="system") # log to prometheus and default (python logger)
log(tag=b, value=1, log_type="system") # log to none of "b" (prometheus does not get trigered, bc different tag)