Warnings Configuration

Centralized warning suppression for the NAICS Embedder package.

Overview

The warnings module provides a single location for configuring warning filters across the entire package. This centralizes PyTorch Lightning and other library warnings that would otherwise be scattered across multiple modules.

Usage

Import and call configure_warnings() at application startup:

from naics_embedder.utils.warnings import configure_warnings

# Apply standard warning filters
configure_warnings()

API Reference

Centralized warning suppression for NAICS Embedder.

This module provides a single location for configuring warning filters across the entire package. Import and call configure_warnings() at application startup to apply consistent suppression rules.

Rationale for Suppressed Warnings:

  1. Precision not supported by model summary (PyTorch Lightning)
  2. Occurs when using mixed precision; the summary still works correctly
  3. Suppressed to reduce noise during training startup

  4. Module in eval mode (PyTorch Lightning)

  5. Warning about frozen modules during training; expected behavior with LoRA
  6. Our architecture intentionally keeps some modules frozen

  7. DataLoader has few workers (PyTorch Lightning)

  8. Triggered on systems with limited resources; not actionable in many cases
  9. Users can adjust num_workers in config if needed

  10. Checkpoint directory exists and is not empty (PyTorch Lightning)

  11. Expected when resuming training or running multiple experiments
  12. Suppressed to keep output clean during normal operation

  13. Trying to infer batch_size (PyTorch Lightning)

  14. Occurs with custom data structures; does not affect functionality
  15. Our collate function returns proper batch structure

Usage:

.. code-block:: python

from naics_embedder.utils.warnings import configure_warnings

# Apply all warning filters at startup
configure_warnings()

configure_warnings(additional_filters=None, verbose=False)

Configure warning filters for the NAICS Embedder application.

Applies the standard set of warning suppressions to reduce noise during training while preserving meaningful warnings from other sources.

Parameters:

Name Type Description Default
additional_filters Optional[List[Tuple[str, type, str]]]

Optional list of additional warning filters to apply. Each tuple should contain (message_pattern, category, module_pattern).

None
verbose bool

If True, log each warning filter as it is applied.

False
Example

from naics_embedder.utils.warnings import configure_warnings configure_warnings() # Apply standard filters

Add custom filter

configure_warnings(additional_filters=[('.my custom warning.', UserWarning, 'my_module')])

get_warning_rationale(pattern)

Get the rationale for a specific warning suppression.

Parameters:

Name Type Description Default
pattern str

The message pattern to look up.

required

Returns:

Type Description
Optional[str]

The rationale string if found, None otherwise.

Example

rationale = get_warning_rationale('.Precision.') print(rationale) 'Mixed precision summary works correctly despite this warning'

list_suppressed_warnings()

List all suppressed warnings and their rationales.

Returns:

Type Description
List[Tuple[str, str]]

List of (pattern, rationale) tuples for documentation purposes.

Example

for pattern, rationale in list_suppressed_warnings(): ... print(f'{pattern}: {rationale}')