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:¶
- Precision not supported by model summary (PyTorch Lightning)
- Occurs when using mixed precision; the summary still works correctly
-
Suppressed to reduce noise during training startup
-
Module in eval mode (PyTorch Lightning)
- Warning about frozen modules during training; expected behavior with LoRA
-
Our architecture intentionally keeps some modules frozen
-
DataLoader has few workers (PyTorch Lightning)
- Triggered on systems with limited resources; not actionable in many cases
-
Users can adjust num_workers in config if needed
-
Checkpoint directory exists and is not empty (PyTorch Lightning)
- Expected when resuming training or running multiple experiments
-
Suppressed to keep output clean during normal operation
-
Trying to infer batch_size (PyTorch Lightning)
- Occurs with custom data structures; does not affect functionality
- 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}')