Skip to content

Commit 51d8d75

Browse files
committed
Updated LocalLab v0.2.1
1 parent d2b2e5e commit 51d8d75

File tree

5 files changed

+53
-66
lines changed

5 files changed

+53
-66
lines changed

CHANGELOG.md

Lines changed: 3 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ All notable changes for version updates.
2828

2929
- Fixed circular import issues between core/app.py and routes modules
3030
- Fixed ngrok authentication flow to properly use auth token from environment variables
31+
- Fixed error with missing torch import in the server.py file
32+
- Added graceful handling of missing torch module to prevent startup failures
3133
- Improved error messages when server fails to start
3234
- Better exception handling throughout the codebase
3335

@@ -108,31 +110,4 @@ All notable changes for version updates.
108110
- Refactored `run_server_proc` in the spawned process to initialize a dedicated logger ("locallab.spawn") to avoid inheriting SemLock objects from a fork context.
109111
- Ensured that the log queue is created using the multiprocessing spawn context, preventing runtime errors in Google Colab.
110112
- Updated Mermaid diagrams in `README.md` and `docs/colab/README.md` to enclose node labels in double quotes, resolving parse errors in GitHub rendering.
111-
- Removed duplicate architecture diagrams from the root `README.md` to streamline documentation.
112-
- Minor improvements to logging and error handling.
113-
114-
## [0.1.2] - 2025-02-25
115-
116-
### Changed
117-
118-
- Updated GitHub Actions workflow to install the Locallab package along with its runtime dependencies in CI.
119-
120-
### Fixed
121-
122-
- Fixed RuntimeError related to SemLock sharing in multiprocessing by clearing logger handlers in `run_server_proc`.
123-
- Updated Mermaid diagrams to wrap node labels in double quotes, improving compatibility with GitHub rendering.
124-
- Improved build status badge aesthetics in the README.
125-
126-
## [0.1.1] - 2025-02-25
127-
128-
### Fixed
129-
130-
- Fixed RuntimeError related to SemLock sharing in multiprocessing by clearing logger handlers in `run_server_proc`.
131-
- Updated Mermaid diagrams to wrap node labels in double quotes, improving compatibility with GitHub rendering.
132-
- Improved build status badge aesthetics in the README.
133-
134-
## [0.1.0] - 2025-02-24
135-
136-
### Added
137-
138-
- Initial release as a Python package with full Google Colab integration, dynamic model loading, robust logging (with ASCII art banners), API endpoints for text generation and system monitoring, Ngrok tunnel management, and comprehensive documentation.
113+
- Removed duplicate architecture diagrams from the root `

locallab/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
LocalLab - A lightweight AI inference server
33
"""
44

5-
__version__ = "0.2.0"
5+
__version__ = "0.2.1"
66

77
from typing import Dict, Any, Optional
88

locallab/server.py

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@
2222
from .logger.logger import set_server_status, log_request
2323
from .utils.system import get_gpu_memory
2424

25+
# Import torch - handle import error gracefully
26+
try:
27+
import torch
28+
TORCH_AVAILABLE = True
29+
except ImportError:
30+
TORCH_AVAILABLE = False
31+
2532
# Get the logger instance
2633
logger = get_logger("locallab.server")
2734

@@ -61,16 +68,21 @@ def check_environment() -> List[Tuple[str, str, bool]]:
6168
))
6269

6370
# Check Colab runtime type for GPU
64-
if not torch.cuda.is_available():
71+
if TORCH_AVAILABLE and not torch.cuda.is_available():
6572
issues.append((
6673
"Running in Colab without GPU acceleration",
6774
"Change runtime type to GPU: Runtime > Change runtime type > Hardware accelerator > GPU",
6875
True
6976
))
77+
elif not TORCH_AVAILABLE:
78+
issues.append((
79+
"PyTorch is not installed",
80+
"Install PyTorch with: pip install torch",
81+
True
82+
))
7083

7184
# Check for CUDA and GPU availability
72-
try:
73-
import torch
85+
if TORCH_AVAILABLE:
7486
if not torch.cuda.is_available():
7587
issues.append((
7688
"CUDA is not available - using CPU for inference",
@@ -86,40 +98,33 @@ def check_environment() -> List[Tuple[str, str, bool]]:
8698
if free_mem < 2000: # Less than 2GB free
8799
issues.append((
88100
f"Low GPU memory: Only {free_mem}MB available",
89-
"Consider using a smaller model or enabling quantization with LOCALLAB_ENABLE_QUANTIZATION=true",
101+
"Models may require 2-6GB of GPU memory. Consider closing other applications or using a smaller model",
90102
True if free_mem < 1000 else False
91103
))
92104
except Exception as e:
93-
issues.append((
94-
f"Failed to check GPU memory: {str(e)}",
95-
"This may indicate driver issues. Consider updating your GPU drivers",
96-
False
97-
))
98-
except ImportError:
105+
logger.warning(f"Failed to check GPU memory: {str(e)}")
106+
else:
99107
issues.append((
100108
"PyTorch is not installed",
101109
"Install PyTorch with: pip install torch",
102110
True
103111
))
104112

105-
# Check available system memory
113+
# Check system memory
106114
try:
107115
import psutil
108116
memory = psutil.virtual_memory()
117+
total_gb = memory.total / (1024 * 1024 * 1024)
109118
available_gb = memory.available / (1024 * 1024 * 1024)
110119

111120
if available_gb < 2.0: # Less than 2GB available
112121
issues.append((
113122
f"Low system memory: Only {available_gb:.1f}GB available",
114-
"Consider closing other applications or using a system with more RAM",
115-
True if available_gb < 1.0 else False
123+
"Models may require 2-8GB of system memory. Consider closing other applications",
124+
True
116125
))
117126
except Exception as e:
118-
issues.append((
119-
f"Failed to check system memory: {str(e)}",
120-
"This may affect model loading and performance",
121-
False
122-
))
127+
pass # Skip if psutil isn't available
123128

124129
# Check for required dependencies
125130
try:

locallab/utils/system.py

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@
44

55
import os
66
import psutil
7-
import torch
7+
try:
8+
import torch
9+
TORCH_AVAILABLE = True
10+
except ImportError:
11+
TORCH_AVAILABLE = False
812
from typing import Optional, Tuple, Dict, Any
913

1014
from ..logger import get_logger
@@ -24,7 +28,7 @@ def get_system_memory() -> Tuple[int, int]:
2428

2529
def get_gpu_memory() -> Optional[Tuple[int, int]]:
2630
"""Get GPU memory information in MB if available"""
27-
if not torch.cuda.is_available():
31+
if not TORCH_AVAILABLE or not torch.cuda.is_available():
2832
return None
2933

3034
try:
@@ -53,7 +57,7 @@ def check_resource_availability(required_memory: int) -> bool:
5357
return False
5458

5559
# If GPU is available, check GPU memory
56-
if torch.cuda.is_available():
60+
if TORCH_AVAILABLE and torch.cuda.is_available():
5761
gpu_memory = get_gpu_memory()
5862
if gpu_memory:
5963
total_gpu, free_gpu = gpu_memory
@@ -64,11 +68,11 @@ def check_resource_availability(required_memory: int) -> bool:
6468
return True
6569

6670

67-
def get_device() -> torch.device:
71+
def get_device() -> str:
6872
"""Get the best available device for computation"""
69-
if torch.cuda.is_available():
70-
return torch.device("cuda")
71-
return torch.device("cpu")
73+
if TORCH_AVAILABLE and torch.cuda.is_available():
74+
return "cuda"
75+
return "cpu"
7276

7377

7478
def format_model_size(size_in_bytes: int) -> str:
@@ -88,19 +92,22 @@ def get_system_resources() -> Dict[str, Any]:
8892
'ram_total': psutil.virtual_memory().total / (1024 * 1024),
8993
'ram_available': psutil.virtual_memory().available / (1024 * 1024),
9094
'memory_usage': psutil.virtual_memory().percent,
91-
'gpu_available': torch.cuda.is_available(),
95+
'gpu_available': False,
9296
'gpu_info': []
9397
}
9498

95-
if resources['gpu_available']:
96-
gpu_count = torch.cuda.device_count()
97-
for i in range(gpu_count):
98-
gpu_mem = get_gpu_memory()
99-
if gpu_mem:
100-
total_mem, _ = gpu_mem
101-
resources['gpu_info'].append({
102-
'name': torch.cuda.get_device_name(i),
103-
'total_memory': total_mem
104-
})
99+
# Update GPU availability only if torch is available
100+
if TORCH_AVAILABLE:
101+
resources['gpu_available'] = torch.cuda.is_available()
102+
if resources['gpu_available']:
103+
gpu_count = torch.cuda.device_count()
104+
for i in range(gpu_count):
105+
gpu_mem = get_gpu_memory()
106+
if gpu_mem:
107+
total_mem, _ = gpu_mem
108+
resources['gpu_info'].append({
109+
'name': torch.cuda.get_device_name(i),
110+
'total_memory': total_mem
111+
})
105112

106113
return resources

setup.py

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

66
setup(
77
name="locallab",
8-
version="0.2.0",
8+
version="0.2.1",
99
packages=find_packages(include=["locallab", "locallab.*"]),
1010
install_requires=[
1111
"fastapi>=0.68.0,<1.0.0",

0 commit comments

Comments
 (0)