ins-pricing 0.4.5__py3-none-any.whl → 0.5.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- ins_pricing/README.md +48 -22
- ins_pricing/__init__.py +142 -90
- ins_pricing/cli/BayesOpt_entry.py +58 -46
- ins_pricing/cli/BayesOpt_incremental.py +77 -110
- ins_pricing/cli/Explain_Run.py +42 -23
- ins_pricing/cli/Explain_entry.py +551 -577
- ins_pricing/cli/Pricing_Run.py +42 -23
- ins_pricing/cli/bayesopt_entry_runner.py +51 -16
- ins_pricing/cli/utils/bootstrap.py +23 -0
- ins_pricing/cli/utils/cli_common.py +256 -256
- ins_pricing/cli/utils/cli_config.py +379 -360
- ins_pricing/cli/utils/import_resolver.py +375 -358
- ins_pricing/cli/utils/notebook_utils.py +256 -242
- ins_pricing/cli/watchdog_run.py +216 -198
- ins_pricing/frontend/__init__.py +10 -10
- ins_pricing/frontend/app.py +132 -61
- ins_pricing/frontend/config_builder.py +33 -0
- ins_pricing/frontend/example_config.json +11 -0
- ins_pricing/frontend/example_workflows.py +1 -1
- ins_pricing/frontend/runner.py +340 -388
- ins_pricing/governance/__init__.py +20 -20
- ins_pricing/governance/release.py +159 -159
- ins_pricing/modelling/README.md +1 -1
- ins_pricing/modelling/__init__.py +147 -92
- ins_pricing/modelling/{core/bayesopt → bayesopt}/README.md +31 -13
- ins_pricing/modelling/{core/bayesopt → bayesopt}/__init__.py +64 -102
- ins_pricing/modelling/{core/bayesopt → bayesopt}/config_components.py +12 -0
- ins_pricing/modelling/{core/bayesopt → bayesopt}/config_preprocess.py +589 -552
- ins_pricing/modelling/{core/bayesopt → bayesopt}/core.py +987 -958
- ins_pricing/modelling/{core/bayesopt → bayesopt}/model_explain_mixin.py +296 -296
- ins_pricing/modelling/{core/bayesopt → bayesopt}/model_plotting_mixin.py +488 -548
- ins_pricing/modelling/{core/bayesopt → bayesopt}/models/__init__.py +27 -27
- ins_pricing/modelling/{core/bayesopt → bayesopt}/models/model_ft_components.py +349 -342
- ins_pricing/modelling/{core/bayesopt → bayesopt}/models/model_ft_trainer.py +921 -913
- ins_pricing/modelling/{core/bayesopt → bayesopt}/models/model_gnn.py +794 -785
- ins_pricing/modelling/{core/bayesopt → bayesopt}/models/model_resn.py +454 -446
- ins_pricing/modelling/bayesopt/trainers/__init__.py +19 -0
- ins_pricing/modelling/{core/bayesopt → bayesopt}/trainers/trainer_base.py +1294 -1282
- ins_pricing/modelling/{core/bayesopt → bayesopt}/trainers/trainer_ft.py +64 -56
- ins_pricing/modelling/{core/bayesopt → bayesopt}/trainers/trainer_glm.py +203 -198
- ins_pricing/modelling/{core/bayesopt → bayesopt}/trainers/trainer_gnn.py +333 -325
- ins_pricing/modelling/{core/bayesopt → bayesopt}/trainers/trainer_resn.py +279 -267
- ins_pricing/modelling/{core/bayesopt → bayesopt}/trainers/trainer_xgb.py +515 -313
- ins_pricing/modelling/bayesopt/utils/__init__.py +67 -0
- ins_pricing/modelling/bayesopt/utils/constants.py +21 -0
- ins_pricing/modelling/{core/bayesopt → bayesopt}/utils/distributed_utils.py +193 -186
- ins_pricing/modelling/bayesopt/utils/io_utils.py +7 -0
- ins_pricing/modelling/bayesopt/utils/losses.py +27 -0
- ins_pricing/modelling/bayesopt/utils/metrics_and_devices.py +17 -0
- ins_pricing/modelling/{core/bayesopt → bayesopt}/utils/torch_trainer_mixin.py +636 -623
- ins_pricing/modelling/{core/evaluation.py → evaluation.py} +113 -104
- ins_pricing/modelling/explain/__init__.py +55 -55
- ins_pricing/modelling/explain/metrics.py +27 -174
- ins_pricing/modelling/explain/permutation.py +237 -237
- ins_pricing/modelling/plotting/__init__.py +40 -36
- ins_pricing/modelling/plotting/compat.py +228 -0
- ins_pricing/modelling/plotting/curves.py +572 -572
- ins_pricing/modelling/plotting/diagnostics.py +163 -163
- ins_pricing/modelling/plotting/geo.py +362 -362
- ins_pricing/modelling/plotting/importance.py +121 -121
- ins_pricing/pricing/__init__.py +27 -27
- ins_pricing/pricing/factors.py +67 -56
- ins_pricing/production/__init__.py +35 -25
- ins_pricing/production/{predict.py → inference.py} +140 -57
- ins_pricing/production/monitoring.py +8 -21
- ins_pricing/reporting/__init__.py +11 -11
- ins_pricing/setup.py +1 -1
- ins_pricing/tests/production/test_inference.py +90 -0
- ins_pricing/utils/__init__.py +112 -78
- ins_pricing/utils/device.py +258 -237
- ins_pricing/utils/features.py +53 -0
- ins_pricing/utils/io.py +72 -0
- ins_pricing/utils/logging.py +34 -1
- ins_pricing/{modelling/core/bayesopt/utils → utils}/losses.py +125 -129
- ins_pricing/utils/metrics.py +158 -24
- ins_pricing/utils/numerics.py +76 -0
- ins_pricing/utils/paths.py +9 -1
- ins_pricing/utils/profiling.py +8 -4
- {ins_pricing-0.4.5.dist-info → ins_pricing-0.5.1.dist-info}/METADATA +1 -1
- ins_pricing-0.5.1.dist-info/RECORD +132 -0
- ins_pricing/modelling/core/BayesOpt.py +0 -146
- ins_pricing/modelling/core/__init__.py +0 -1
- ins_pricing/modelling/core/bayesopt/trainers/__init__.py +0 -19
- ins_pricing/modelling/core/bayesopt/utils/__init__.py +0 -86
- ins_pricing/modelling/core/bayesopt/utils/constants.py +0 -183
- ins_pricing/modelling/core/bayesopt/utils/io_utils.py +0 -126
- ins_pricing/modelling/core/bayesopt/utils/metrics_and_devices.py +0 -555
- ins_pricing/modelling/core/bayesopt/utils.py +0 -105
- ins_pricing/modelling/core/bayesopt/utils_backup.py +0 -1503
- ins_pricing/tests/production/test_predict.py +0 -233
- ins_pricing-0.4.5.dist-info/RECORD +0 -130
- {ins_pricing-0.4.5.dist-info → ins_pricing-0.5.1.dist-info}/WHEEL +0 -0
- {ins_pricing-0.4.5.dist-info → ins_pricing-0.5.1.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"""Backward compatibility re-exports for bayesopt utilities.
|
|
2
|
+
|
|
3
|
+
This module keeps legacy imports working while routing general helpers
|
|
4
|
+
through ins_pricing.utils and leaving bayesopt-specific utilities in place.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
# Constants and simple utilities
|
|
10
|
+
from ins_pricing.modelling.bayesopt.utils.constants import (
|
|
11
|
+
EPS,
|
|
12
|
+
set_global_seed,
|
|
13
|
+
ensure_parent_dir,
|
|
14
|
+
compute_batch_size,
|
|
15
|
+
tweedie_loss,
|
|
16
|
+
infer_factor_and_cate_list,
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
# I/O utilities
|
|
20
|
+
from ins_pricing.modelling.bayesopt.utils.io_utils import (
|
|
21
|
+
IOUtils,
|
|
22
|
+
csv_to_dict,
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
# Distributed training
|
|
26
|
+
from ins_pricing.modelling.bayesopt.utils.distributed_utils import (
|
|
27
|
+
DistributedUtils,
|
|
28
|
+
TrainingUtils,
|
|
29
|
+
free_cuda,
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
# PyTorch training mixin
|
|
33
|
+
from ins_pricing.modelling.bayesopt.utils.torch_trainer_mixin import (
|
|
34
|
+
TorchTrainerMixin,
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
# Metrics and device helpers (shared utilities)
|
|
38
|
+
from ins_pricing.modelling.bayesopt.utils.metrics_and_devices import (
|
|
39
|
+
get_logger,
|
|
40
|
+
MetricFactory,
|
|
41
|
+
GPUMemoryManager,
|
|
42
|
+
DeviceManager,
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
__all__ = [
|
|
46
|
+
# Constants
|
|
47
|
+
'EPS',
|
|
48
|
+
'set_global_seed',
|
|
49
|
+
'ensure_parent_dir',
|
|
50
|
+
'compute_batch_size',
|
|
51
|
+
'tweedie_loss',
|
|
52
|
+
'infer_factor_and_cate_list',
|
|
53
|
+
# I/O
|
|
54
|
+
'IOUtils',
|
|
55
|
+
'csv_to_dict',
|
|
56
|
+
# Distributed
|
|
57
|
+
'DistributedUtils',
|
|
58
|
+
'TrainingUtils',
|
|
59
|
+
'free_cuda',
|
|
60
|
+
# PyTorch
|
|
61
|
+
'TorchTrainerMixin',
|
|
62
|
+
# Utilities
|
|
63
|
+
'get_logger',
|
|
64
|
+
'MetricFactory',
|
|
65
|
+
'GPUMemoryManager',
|
|
66
|
+
'DeviceManager',
|
|
67
|
+
]
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"""Backward-compatible re-exports for numerical utilities."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from ins_pricing.utils.features import infer_factor_and_cate_list
|
|
6
|
+
from ins_pricing.utils.io import ensure_parent_dir
|
|
7
|
+
from ins_pricing.utils.numerics import (
|
|
8
|
+
EPS,
|
|
9
|
+
compute_batch_size,
|
|
10
|
+
set_global_seed,
|
|
11
|
+
tweedie_loss,
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
__all__ = [
|
|
15
|
+
"EPS",
|
|
16
|
+
"set_global_seed",
|
|
17
|
+
"ensure_parent_dir",
|
|
18
|
+
"compute_batch_size",
|
|
19
|
+
"tweedie_loss",
|
|
20
|
+
"infer_factor_and_cate_list",
|
|
21
|
+
]
|
|
@@ -1,186 +1,193 @@
|
|
|
1
|
-
"""Distributed training utilities for PyTorch DDP.
|
|
2
|
-
|
|
3
|
-
This module contains:
|
|
4
|
-
- DistributedUtils for DDP setup and process coordination
|
|
5
|
-
- TrainingUtils for CUDA memory management
|
|
6
|
-
- free_cuda() for legacy compatibility
|
|
7
|
-
"""
|
|
8
|
-
|
|
9
|
-
from __future__ import annotations
|
|
10
|
-
|
|
11
|
-
import gc
|
|
12
|
-
import os
|
|
13
|
-
from datetime import timedelta
|
|
14
|
-
from typing import Optional
|
|
15
|
-
|
|
16
|
-
import torch
|
|
17
|
-
import torch.distributed as dist
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
return "
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
return
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
"""
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
)
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
@staticmethod
|
|
130
|
-
def
|
|
131
|
-
"""
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
1
|
+
"""Distributed training utilities for PyTorch DDP.
|
|
2
|
+
|
|
3
|
+
This module contains:
|
|
4
|
+
- DistributedUtils for DDP setup and process coordination
|
|
5
|
+
- TrainingUtils for CUDA memory management
|
|
6
|
+
- free_cuda() for legacy compatibility
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
import gc
|
|
12
|
+
import os
|
|
13
|
+
from datetime import timedelta
|
|
14
|
+
from typing import Optional
|
|
15
|
+
|
|
16
|
+
import torch
|
|
17
|
+
import torch.distributed as dist
|
|
18
|
+
from ins_pricing.utils import get_logger, log_print
|
|
19
|
+
|
|
20
|
+
_logger = get_logger("ins_pricing.modelling.bayesopt.utils.distributed_utils")
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def _log(*args, **kwargs) -> None:
|
|
24
|
+
log_print(_logger, *args, **kwargs)
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def _select_ddp_backend() -> str:
|
|
28
|
+
"""Select the appropriate DDP backend based on system capabilities.
|
|
29
|
+
|
|
30
|
+
Returns:
|
|
31
|
+
"nccl" if CUDA is available and NCCL is supported (non-Windows),
|
|
32
|
+
otherwise "gloo"
|
|
33
|
+
"""
|
|
34
|
+
if not torch.cuda.is_available():
|
|
35
|
+
return "gloo"
|
|
36
|
+
|
|
37
|
+
if os.name == "nt": # Windows doesn't support NCCL
|
|
38
|
+
return "gloo"
|
|
39
|
+
|
|
40
|
+
try:
|
|
41
|
+
nccl_available = getattr(dist, "is_nccl_available", lambda: False)()
|
|
42
|
+
return "nccl" if nccl_available else "gloo"
|
|
43
|
+
except Exception:
|
|
44
|
+
return "gloo"
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def _get_ddp_timeout() -> timedelta:
|
|
48
|
+
"""Get the DDP timeout from environment variable.
|
|
49
|
+
|
|
50
|
+
Returns:
|
|
51
|
+
timedelta for DDP timeout (default: 1800 seconds)
|
|
52
|
+
"""
|
|
53
|
+
timeout_seconds = int(os.environ.get("BAYESOPT_DDP_TIMEOUT_SECONDS", "1800"))
|
|
54
|
+
return timedelta(seconds=max(1, timeout_seconds))
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def _cache_ddp_state(local_rank: int, rank: int, world_size: int) -> tuple:
|
|
58
|
+
"""Cache and return DDP state tuple."""
|
|
59
|
+
state = (True, local_rank, rank, world_size)
|
|
60
|
+
DistributedUtils._cached_state = state
|
|
61
|
+
return state
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
class DistributedUtils:
|
|
65
|
+
"""Utilities for distributed data parallel training.
|
|
66
|
+
|
|
67
|
+
This class provides methods for:
|
|
68
|
+
- Initializing DDP process groups
|
|
69
|
+
- Checking process rank and world size
|
|
70
|
+
- Cleanup after distributed training
|
|
71
|
+
"""
|
|
72
|
+
|
|
73
|
+
_cached_state: Optional[tuple] = None
|
|
74
|
+
|
|
75
|
+
@staticmethod
|
|
76
|
+
def setup_ddp():
|
|
77
|
+
"""Initialize the DDP process group for distributed training.
|
|
78
|
+
|
|
79
|
+
Returns:
|
|
80
|
+
Tuple of (success, local_rank, rank, world_size)
|
|
81
|
+
"""
|
|
82
|
+
# Return cached state if already initialized
|
|
83
|
+
if dist.is_initialized():
|
|
84
|
+
if DistributedUtils._cached_state is None:
|
|
85
|
+
DistributedUtils._cached_state = _cache_ddp_state(
|
|
86
|
+
int(os.environ.get("LOCAL_RANK", 0)),
|
|
87
|
+
dist.get_rank(),
|
|
88
|
+
dist.get_world_size(),
|
|
89
|
+
)
|
|
90
|
+
return DistributedUtils._cached_state
|
|
91
|
+
|
|
92
|
+
# Check for required environment variables
|
|
93
|
+
if 'RANK' not in os.environ or 'WORLD_SIZE' not in os.environ:
|
|
94
|
+
_log(
|
|
95
|
+
f">>> DDP Setup Failed: RANK or WORLD_SIZE not found in env. "
|
|
96
|
+
f"Keys found: {list(os.environ.keys())}"
|
|
97
|
+
)
|
|
98
|
+
_log(">>> Hint: launch with torchrun --nproc_per_node=<N> <script.py>")
|
|
99
|
+
return False, 0, 0, 1
|
|
100
|
+
|
|
101
|
+
rank = int(os.environ["RANK"])
|
|
102
|
+
world_size = int(os.environ["WORLD_SIZE"])
|
|
103
|
+
local_rank = int(os.environ.get("LOCAL_RANK", 0))
|
|
104
|
+
|
|
105
|
+
# Windows CUDA DDP is not supported
|
|
106
|
+
if os.name == "nt" and torch.cuda.is_available() and world_size > 1:
|
|
107
|
+
_log(
|
|
108
|
+
">>> DDP Setup Disabled: Windows CUDA DDP is not supported. "
|
|
109
|
+
"Falling back to single process."
|
|
110
|
+
)
|
|
111
|
+
return False, 0, 0, 1
|
|
112
|
+
|
|
113
|
+
# Set CUDA device for this process
|
|
114
|
+
if torch.cuda.is_available():
|
|
115
|
+
torch.cuda.set_device(local_rank)
|
|
116
|
+
|
|
117
|
+
# Initialize process group
|
|
118
|
+
backend = _select_ddp_backend()
|
|
119
|
+
timeout = _get_ddp_timeout()
|
|
120
|
+
|
|
121
|
+
dist.init_process_group(backend=backend, init_method="env://", timeout=timeout)
|
|
122
|
+
_log(
|
|
123
|
+
f">>> DDP Initialized ({backend}, timeout={timeout.total_seconds():.0f}s): "
|
|
124
|
+
f"Rank {rank}/{world_size}, Local Rank {local_rank}"
|
|
125
|
+
)
|
|
126
|
+
|
|
127
|
+
return _cache_ddp_state(local_rank, rank, world_size)
|
|
128
|
+
|
|
129
|
+
@staticmethod
|
|
130
|
+
def cleanup_ddp():
|
|
131
|
+
"""Destroy the DDP process group and clear cached state."""
|
|
132
|
+
if dist.is_initialized():
|
|
133
|
+
dist.destroy_process_group()
|
|
134
|
+
DistributedUtils._cached_state = None
|
|
135
|
+
|
|
136
|
+
@staticmethod
|
|
137
|
+
def is_main_process():
|
|
138
|
+
"""Check if current process is rank 0 (main process).
|
|
139
|
+
|
|
140
|
+
Returns:
|
|
141
|
+
True if main process or DDP not initialized
|
|
142
|
+
"""
|
|
143
|
+
return not dist.is_initialized() or dist.get_rank() == 0
|
|
144
|
+
|
|
145
|
+
@staticmethod
|
|
146
|
+
def world_size() -> int:
|
|
147
|
+
"""Get the total number of processes in the distributed group.
|
|
148
|
+
|
|
149
|
+
Returns:
|
|
150
|
+
World size (1 if DDP not initialized)
|
|
151
|
+
"""
|
|
152
|
+
return dist.get_world_size() if dist.is_initialized() else 1
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
class TrainingUtils:
|
|
156
|
+
"""General training utilities including CUDA management."""
|
|
157
|
+
|
|
158
|
+
@staticmethod
|
|
159
|
+
def free_cuda() -> None:
|
|
160
|
+
"""Release CUDA memory and clear cache.
|
|
161
|
+
|
|
162
|
+
This performs aggressive cleanup:
|
|
163
|
+
1. Move all PyTorch models to CPU
|
|
164
|
+
2. Run garbage collection
|
|
165
|
+
3. Clear CUDA cache
|
|
166
|
+
"""
|
|
167
|
+
_log(">>> Moving all models to CPU...")
|
|
168
|
+
for obj in gc.get_objects():
|
|
169
|
+
try:
|
|
170
|
+
if hasattr(obj, "to") and callable(obj.to):
|
|
171
|
+
obj.to("cpu")
|
|
172
|
+
except Exception:
|
|
173
|
+
pass
|
|
174
|
+
|
|
175
|
+
_log(">>> Releasing tensor/optimizer/DataLoader references...")
|
|
176
|
+
gc.collect()
|
|
177
|
+
|
|
178
|
+
_log(">>> Clearing CUDA cache...")
|
|
179
|
+
if torch.cuda.is_available():
|
|
180
|
+
torch.cuda.empty_cache()
|
|
181
|
+
torch.cuda.synchronize()
|
|
182
|
+
_log(">>> CUDA memory released.")
|
|
183
|
+
else:
|
|
184
|
+
_log(">>> CUDA not available; cleanup skipped.")
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
# Backward compatibility function wrapper
|
|
188
|
+
def free_cuda():
|
|
189
|
+
"""Legacy function wrapper for CUDA memory cleanup.
|
|
190
|
+
|
|
191
|
+
This function calls TrainingUtils.free_cuda() for backward compatibility.
|
|
192
|
+
"""
|
|
193
|
+
TrainingUtils.free_cuda()
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"""Backward-compatible re-exports for loss utilities."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from ins_pricing.utils.losses import (
|
|
6
|
+
CLASSIFICATION_LOSSES,
|
|
7
|
+
LOSS_ALIASES,
|
|
8
|
+
REGRESSION_LOSSES,
|
|
9
|
+
infer_loss_name_from_model_name,
|
|
10
|
+
loss_requires_positive,
|
|
11
|
+
normalize_loss_name,
|
|
12
|
+
regression_loss,
|
|
13
|
+
resolve_tweedie_power,
|
|
14
|
+
resolve_xgb_objective,
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
__all__ = [
|
|
18
|
+
"LOSS_ALIASES",
|
|
19
|
+
"REGRESSION_LOSSES",
|
|
20
|
+
"CLASSIFICATION_LOSSES",
|
|
21
|
+
"normalize_loss_name",
|
|
22
|
+
"infer_loss_name_from_model_name",
|
|
23
|
+
"resolve_tweedie_power",
|
|
24
|
+
"resolve_xgb_objective",
|
|
25
|
+
"regression_loss",
|
|
26
|
+
"loss_requires_positive",
|
|
27
|
+
]
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"""Backward-compatible re-exports for metrics and device utilities."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from ins_pricing.utils import (
|
|
6
|
+
DeviceManager,
|
|
7
|
+
GPUMemoryManager,
|
|
8
|
+
MetricFactory,
|
|
9
|
+
get_logger,
|
|
10
|
+
)
|
|
11
|
+
|
|
12
|
+
__all__ = [
|
|
13
|
+
"get_logger",
|
|
14
|
+
"MetricFactory",
|
|
15
|
+
"GPUMemoryManager",
|
|
16
|
+
"DeviceManager",
|
|
17
|
+
]
|