Skip to content

Commit 7be9307

Browse files
committed
Improved Version Handling
1 parent 3408301 commit 7be9307

File tree

5 files changed

+89
-11
lines changed

5 files changed

+89
-11
lines changed

CHANGELOG.md

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,28 @@
22

33
All notable changes to LocalLab will be documented in this file.
44

5-
## [0.6.5] - 2025-05-16
5+
## [0.6.6] - 2025-05-16
66

77
### Fixed
88

99
- Fixed critical error with Hugging Face progress bars display
10+
- Added robust version-agnostic approach to enable progress bars
11+
- Implemented multiple fallback methods for different huggingface_hub versions
12+
- Fixed AttributeError with huggingface_hub.utils.logging module
13+
- Added direct environment variable configuration for maximum compatibility
14+
- Enhanced error handling during model downloads
15+
- Improved early configuration system to properly set up logging
16+
17+
### Changed
18+
1019
- Corrected function naming and imports for better compatibility
20+
21+
## [0.6.5] - 2025-05-16
22+
23+
### Fixed
24+
25+
- Fixed critical error with Hugging Face progress bars display
1126
- Improved early configuration system to properly set up logging
12-
- Enhanced error handling during model downloads
13-
- Fixed AttributeError with huggingface_hub module
1427

1528
## [0.6.4] - 2025-05-16
1629

locallab/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# This ensures Hugging Face's progress bars are displayed correctly
77
from .utils.early_config import configure_hf_logging
88

9-
__version__ = "0.6.5" # Fixed Hugging Face progress bars display and improved model downloading experience
9+
__version__ = "0.6.6" # Fixed Hugging Face progress bars display with version-agnostic approach
1010

1111
# Only import what's necessary initially, lazy-load the rest
1212
from .logger import get_logger

locallab/model_manager.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,9 @@ async def _load_model_with_optimizations(self, model_id: str):
278278
print(f"\n{Fore.CYAN}Starting model download - native progress bars will appear below{Style.RESET_ALL}\n")
279279

280280
# Enable Hugging Face progress bars again to ensure they're properly configured
281+
# Set environment variables directly for maximum compatibility
282+
os.environ["HF_HUB_DISABLE_PROGRESS_BARS"] = "0"
283+
os.environ["TRANSFORMERS_NO_PROGRESS_BAR"] = "0"
281284
configure_hf_progress_bars()
282285

283286
# Use a context manager to ensure proper display of Hugging Face progress bars
@@ -1093,6 +1096,9 @@ async def load_custom_model(self, model_name: str, fallback_model: Optional[str]
10931096
print(f"\n{Fore.CYAN}Starting custom model download - native progress bars will appear below{Style.RESET_ALL}\n")
10941097

10951098
# Enable Hugging Face progress bars again to ensure they're properly configured
1099+
# Set environment variables directly for maximum compatibility
1100+
os.environ["HF_HUB_DISABLE_PROGRESS_BARS"] = "0"
1101+
os.environ["TRANSFORMERS_NO_PROGRESS_BAR"] = "0"
10961102
configure_hf_progress_bars()
10971103

10981104
# Use a context manager to ensure proper display of Hugging Face progress bars

locallab/utils/early_config.py

Lines changed: 65 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,24 @@ def enable_hf_progress_bars():
8787
# Configure huggingface_hub
8888
try:
8989
import huggingface_hub
90-
# The correct way to enable progress bars in huggingface_hub
91-
from huggingface_hub.utils import logging as hf_logging
92-
hf_logging.enable_progress_bars()
90+
91+
# Different versions of huggingface_hub have different ways to enable progress bars
92+
# Try multiple approaches to ensure compatibility
93+
94+
# Method 1: Try direct module function (newer versions)
95+
if hasattr(huggingface_hub, "enable_progress_bars"):
96+
huggingface_hub.enable_progress_bars()
97+
98+
# Method 2: Try through utils.logging (some versions)
99+
try:
100+
from huggingface_hub.utils import logging as hf_logging
101+
if hasattr(hf_logging, "enable_progress_bars"):
102+
hf_logging.enable_progress_bars()
103+
except (ImportError, AttributeError):
104+
pass
105+
106+
# Method 3: Set environment variable (works for all versions)
107+
os.environ["HF_HUB_DISABLE_PROGRESS_BARS"] = "0"
93108

94109
# Also enable HF Transfer for better download experience
95110
if hasattr(huggingface_hub, "constants"):
@@ -100,13 +115,57 @@ def enable_hf_progress_bars():
100115
# Configure transformers
101116
try:
102117
import transformers
103-
transformers.utils.logging.enable_progress_bar()
104-
transformers.logging.set_verbosity_warning()
118+
119+
# Different versions of transformers have different ways to enable progress bars
120+
# Try multiple approaches to ensure compatibility
121+
122+
# Method 1: Try through utils.logging (newer versions)
123+
try:
124+
if hasattr(transformers.utils.logging, "enable_progress_bar"):
125+
transformers.utils.logging.enable_progress_bar()
126+
except (ImportError, AttributeError):
127+
pass
128+
129+
# Method 2: Try direct module function (some versions)
130+
if hasattr(transformers, "enable_progress_bars"):
131+
transformers.enable_progress_bars()
132+
133+
# Method 3: Set environment variable (works for all versions)
134+
os.environ["TRANSFORMERS_VERBOSITY"] = "warning"
135+
os.environ["TRANSFORMERS_NO_PROGRESS_BAR"] = "0"
136+
137+
# Set verbosity level if available
138+
if hasattr(transformers, "logging") and hasattr(transformers.logging, "set_verbosity_warning"):
139+
transformers.logging.set_verbosity_warning()
105140
except ImportError:
106141
pass
107142

108143
# Alias for backward compatibility
109144
configure_hf_progress_bars = enable_hf_progress_bars
110145

111-
# Export the configure_hf_logging function for use in __init__.py
146+
# Function to configure Hugging Face logging
147+
def configure_hf_logging():
148+
"""
149+
Configure Hugging Face logging.
150+
This function is called from __init__.py to set up logging early.
151+
"""
152+
# Configure logging for Hugging Face libraries
153+
for logger_name in ["transformers", "huggingface_hub", "accelerate", "tqdm", "filelock"]:
154+
hf_logger = logging.getLogger(logger_name)
155+
hf_logger.setLevel(logging.WARNING) # Only show warnings and errors
156+
hf_logger.propagate = False # Don't propagate to parent loggers
157+
158+
# Remove any existing handlers
159+
for handler in hf_logger.handlers[:]:
160+
hf_logger.removeHandler(handler)
161+
162+
# Add a null handler to prevent warnings about no handlers
163+
hf_logger.addHandler(logging.NullHandler())
164+
165+
# Set environment variables for better compatibility
166+
os.environ["HF_HUB_DISABLE_PROGRESS_BARS"] = "0" # Enable progress bars
167+
os.environ["TRANSFORMERS_VERBOSITY"] = "warning" # Set verbosity level
168+
os.environ["TRANSFORMERS_NO_PROGRESS_BAR"] = "0" # Enable progress bars
169+
170+
# Export functions for use in other modules
112171
__all__ = ["enable_hf_progress_bars", "configure_hf_progress_bars", "configure_hf_logging", "StdoutRedirector"]

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747

4848
setup(
4949
name="locallab",
50-
version="0.6.5",
50+
version="0.6.6",
5151
packages=find_packages(include=["locallab", "locallab.*"]),
5252
install_requires=install_requires,
5353
extras_require={

0 commit comments

Comments
 (0)