-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathbase_gpu_controller.py
More file actions
59 lines (50 loc) · 2.04 KB
/
base_gpu_controller.py
File metadata and controls
59 lines (50 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
from typing import Union
from keep_gpu.utilities.humanized_input import parse_size
class BaseGPUController:
def __init__(self, vram_to_keep: Union[int, str], interval: float):
"""
Base class for GPU controllers.
Args:
vram_to_keep (int or str): Amount of VRAM to keep busy. Accepts integers
(tensor element count) or human strings like "1GiB" (converted to
element count for float32 tensors).
interval (float): Time interval (in seconds) between keep-alive cycles.
"""
if isinstance(vram_to_keep, str):
vram_to_keep = parse_size(vram_to_keep)
elif not isinstance(vram_to_keep, int):
raise TypeError(
f"vram_to_keep must be str or int, got {type(vram_to_keep)}"
)
self.vram_to_keep = vram_to_keep
self.interval = interval
def monitor(self):
"""
Method to monitor GPU state.
Should be implemented by subclasses.
"""
raise NotImplementedError("Subclasses must implement this method.")
def keep(self):
"""
Method to keep the specified amount of VRAM busy/occupied.
Should be implemented by subclasses.
"""
raise NotImplementedError("Subclasses must implement this method.")
def rest(self):
"""
Method to rest or pause the controller.
Should be implemented by subclasses.
"""
raise NotImplementedError("Subclasses must implement this method.")
async def _keep(self):
"""
Asynchronous method to keep the specified amount of VRAM busy/occupied.
This is a placeholder for subclasses to implement their logic.
"""
raise NotImplementedError("Subclasses must implement this method.")
async def _rest(self):
"""
Asynchronous method to rest or pause the controller.
This is a placeholder for subclasses to implement their logic.
"""
raise NotImplementedError("Subclasses must implement this method.")