MCPcopy Create free account
hub / github.com/aigc3d/LHM / __init__

Method __init__

LHM/utils/model_query_utils.py:32–55  ·  view source on GitHub ↗

Initialize the model switcher. Args: model_requirements (dict): {model_name: min_required_memory(MB)} get_memory_func (callable, optional): Custom function to check available GPU memory extra_memory (int, optional): Additional memory buffer to res

(self, model_requirements, get_memory_func=None, extra_memory=0)

Source from the content-addressed store, hash-verified

30 """
31
32 def __init__(self, model_requirements, get_memory_func=None, extra_memory=0):
33 """Initialize the model switcher.
34
35 Args:
36 model_requirements (dict): {model_name: min_required_memory(MB)}
37 get_memory_func (callable, optional): Custom function to check available GPU memory
38 extra_memory (int, optional): Additional memory buffer to reserve (MB)
39 """
40 self.model_requirements = model_requirements
41 # Sort models by: 1. Memory requirements (descending) 2. HF models first
42 self.sorted_models = sorted(
43 model_requirements.items(),
44 key=lambda x: (-x[1], '-HF' not in x[0])
45 )
46
47 self.extra_memory = extra_memory
48
49 # Initialize memory checking method
50 if get_memory_func is None:
51 self.get_memory = self._default_memory_check
52 else:
53 self.get_memory = get_memory_func
54
55 self.available_mb = self._default_memory_check()
56
57 def _default_memory_check(self, gpu_id=0):
58 """Check available GPU memory using GPUtil.

Callers

nothing calls this directly

Calls 2

_default_memory_checkMethod · 0.95
itemsMethod · 0.45

Tested by

no test coverage detected