ins-pricing 0.3.2__py3-none-any.whl → 0.3.3__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/cli/BayesOpt_entry.py +32 -0
- ins_pricing/cli/utils/import_resolver.py +29 -3
- ins_pricing/cli/utils/notebook_utils.py +3 -2
- ins_pricing/modelling/core/bayesopt/__init__.py +4 -0
- ins_pricing/modelling/core/bayesopt/models/model_ft_components.py +38 -12
- ins_pricing/setup.py +1 -1
- ins_pricing/utils/torch_compat.py +40 -0
- {ins_pricing-0.3.2.dist-info → ins_pricing-0.3.3.dist-info}/METADATA +1 -1
- {ins_pricing-0.3.2.dist-info → ins_pricing-0.3.3.dist-info}/RECORD +11 -11
- {ins_pricing-0.3.2.dist-info → ins_pricing-0.3.3.dist-info}/WHEEL +0 -0
- {ins_pricing-0.3.2.dist-info → ins_pricing-0.3.3.dist-info}/top_level.txt +0 -0
|
@@ -6,6 +6,8 @@ The main implementation lives in bayesopt_entry_runner.py.
|
|
|
6
6
|
from __future__ import annotations
|
|
7
7
|
|
|
8
8
|
from pathlib import Path
|
|
9
|
+
import json
|
|
10
|
+
import os
|
|
9
11
|
import sys
|
|
10
12
|
|
|
11
13
|
if __package__ in {None, ""}:
|
|
@@ -13,6 +15,36 @@ if __package__ in {None, ""}:
|
|
|
13
15
|
if str(repo_root) not in sys.path:
|
|
14
16
|
sys.path.insert(0, str(repo_root))
|
|
15
17
|
|
|
18
|
+
def _apply_env_from_config(argv: list[str]) -> None:
|
|
19
|
+
if "--config-json" not in argv:
|
|
20
|
+
return
|
|
21
|
+
idx = argv.index("--config-json")
|
|
22
|
+
if idx + 1 >= len(argv):
|
|
23
|
+
return
|
|
24
|
+
raw_path = argv[idx + 1]
|
|
25
|
+
try:
|
|
26
|
+
cfg_path = Path(raw_path).expanduser()
|
|
27
|
+
if not cfg_path.is_absolute():
|
|
28
|
+
cfg_path = cfg_path.resolve()
|
|
29
|
+
if not cfg_path.exists():
|
|
30
|
+
script_dir = Path(__file__).resolve().parents[1]
|
|
31
|
+
candidate = (script_dir / raw_path).resolve()
|
|
32
|
+
if candidate.exists():
|
|
33
|
+
cfg_path = candidate
|
|
34
|
+
if not cfg_path.exists():
|
|
35
|
+
return
|
|
36
|
+
cfg = json.loads(cfg_path.read_text(encoding="utf-8", errors="replace"))
|
|
37
|
+
env = cfg.get("env", {})
|
|
38
|
+
if isinstance(env, dict):
|
|
39
|
+
for key, value in env.items():
|
|
40
|
+
if key is None:
|
|
41
|
+
continue
|
|
42
|
+
os.environ.setdefault(str(key), str(value))
|
|
43
|
+
except Exception:
|
|
44
|
+
return
|
|
45
|
+
|
|
46
|
+
_apply_env_from_config(sys.argv)
|
|
47
|
+
|
|
16
48
|
try:
|
|
17
49
|
from .bayesopt_entry_runner import main
|
|
18
50
|
except Exception: # pragma: no cover
|
|
@@ -13,6 +13,7 @@ Usage:
|
|
|
13
13
|
from __future__ import annotations
|
|
14
14
|
|
|
15
15
|
import importlib
|
|
16
|
+
import os
|
|
16
17
|
import sys
|
|
17
18
|
from dataclasses import dataclass, field
|
|
18
19
|
from pathlib import Path
|
|
@@ -70,14 +71,39 @@ class ResolvedImports:
|
|
|
70
71
|
plot_loss_curve: Optional[Callable] = None
|
|
71
72
|
|
|
72
73
|
|
|
74
|
+
def _debug_imports_enabled() -> bool:
|
|
75
|
+
value = os.environ.get("BAYESOPT_DEBUG_IMPORTS")
|
|
76
|
+
if value is None:
|
|
77
|
+
return False
|
|
78
|
+
return str(value).strip().lower() in {"1", "true", "yes", "y", "on"}
|
|
79
|
+
|
|
80
|
+
|
|
73
81
|
def _try_import(module_path: str, attr_name: Optional[str] = None) -> Optional[Any]:
|
|
74
82
|
"""Attempt to import a module or attribute, returning None on failure."""
|
|
75
83
|
try:
|
|
76
84
|
module = importlib.import_module(module_path)
|
|
77
85
|
if attr_name:
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
86
|
+
result = getattr(module, attr_name, None)
|
|
87
|
+
else:
|
|
88
|
+
result = module
|
|
89
|
+
if _debug_imports_enabled():
|
|
90
|
+
origin = getattr(module, "__file__", None)
|
|
91
|
+
origin = origin or getattr(module, "__path__", None)
|
|
92
|
+
print(
|
|
93
|
+
f"[BAYESOPT_DEBUG_IMPORTS] imported {module_path}"
|
|
94
|
+
f"{'::' + attr_name if attr_name else ''} from {origin}",
|
|
95
|
+
file=sys.stderr,
|
|
96
|
+
flush=True,
|
|
97
|
+
)
|
|
98
|
+
return result
|
|
99
|
+
except Exception as exc:
|
|
100
|
+
if _debug_imports_enabled():
|
|
101
|
+
print(
|
|
102
|
+
f"[BAYESOPT_DEBUG_IMPORTS] failed import {module_path}"
|
|
103
|
+
f"{'::' + attr_name if attr_name else ''}: {exc.__class__.__name__}: {exc}",
|
|
104
|
+
file=sys.stderr,
|
|
105
|
+
flush=True,
|
|
106
|
+
)
|
|
81
107
|
return None
|
|
82
108
|
|
|
83
109
|
|
|
@@ -8,9 +8,9 @@ from pathlib import Path
|
|
|
8
8
|
from typing import Iterable, List, Optional, Sequence, cast
|
|
9
9
|
|
|
10
10
|
try:
|
|
11
|
-
from .cli_config import add_config_json_arg # type: ignore
|
|
11
|
+
from .cli_config import add_config_json_arg, set_env # type: ignore
|
|
12
12
|
except Exception: # pragma: no cover
|
|
13
|
-
from cli_config import add_config_json_arg # type: ignore
|
|
13
|
+
from cli_config import add_config_json_arg, set_env # type: ignore
|
|
14
14
|
|
|
15
15
|
|
|
16
16
|
def _find_ins_pricing_dir(cwd: Optional[Path] = None) -> Path:
|
|
@@ -261,6 +261,7 @@ def run_from_config(config_json: str | Path) -> subprocess.CompletedProcess:
|
|
|
261
261
|
if not config_path.is_absolute():
|
|
262
262
|
config_path = (pkg_dir / config_path).resolve() if (pkg_dir / config_path).exists() else config_path.resolve()
|
|
263
263
|
raw = json.loads(config_path.read_text(encoding="utf-8", errors="replace"))
|
|
264
|
+
set_env(raw.get("env", {}))
|
|
264
265
|
runner = cast(dict, raw.get("runner") or {})
|
|
265
266
|
|
|
266
267
|
mode = str(runner.get("mode") or "entry").strip().lower()
|
|
@@ -106,31 +106,58 @@ class ScaledTransformerEncoderLayer(nn.Module):
|
|
|
106
106
|
self.res_scale_attn = residual_scale_attn
|
|
107
107
|
self.res_scale_ffn = residual_scale_ffn
|
|
108
108
|
|
|
109
|
-
def forward(self, src, src_mask=None, src_key_padding_mask=None):
|
|
109
|
+
def forward(self, src, src_mask=None, src_key_padding_mask=None, is_causal: Optional[bool] = None, **_kwargs):
|
|
110
110
|
# Input tensor shape: (batch, seq_len, d_model).
|
|
111
111
|
x = src
|
|
112
112
|
|
|
113
113
|
if self.norm_first:
|
|
114
114
|
# Pre-norm before attention.
|
|
115
|
-
x = x + self._sa_block(
|
|
116
|
-
|
|
115
|
+
x = x + self._sa_block(
|
|
116
|
+
self.norm1(x),
|
|
117
|
+
src_mask,
|
|
118
|
+
src_key_padding_mask,
|
|
119
|
+
is_causal=is_causal,
|
|
120
|
+
)
|
|
117
121
|
x = x + self._ff_block(self.norm2(x))
|
|
118
122
|
else:
|
|
119
123
|
# Post-norm (usually disabled).
|
|
120
124
|
x = self.norm1(
|
|
121
|
-
x + self._sa_block(
|
|
125
|
+
x + self._sa_block(
|
|
126
|
+
x,
|
|
127
|
+
src_mask,
|
|
128
|
+
src_key_padding_mask,
|
|
129
|
+
is_causal=is_causal,
|
|
130
|
+
)
|
|
131
|
+
)
|
|
122
132
|
x = self.norm2(x + self._ff_block(x))
|
|
123
133
|
|
|
124
134
|
return x
|
|
125
135
|
|
|
126
|
-
def _sa_block(self, x, attn_mask, key_padding_mask):
|
|
136
|
+
def _sa_block(self, x, attn_mask, key_padding_mask, *, is_causal: Optional[bool] = None):
|
|
127
137
|
# Self-attention with residual scaling.
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
138
|
+
if is_causal is None:
|
|
139
|
+
attn_out, _ = self.self_attn(
|
|
140
|
+
x, x, x,
|
|
141
|
+
attn_mask=attn_mask,
|
|
142
|
+
key_padding_mask=key_padding_mask,
|
|
143
|
+
need_weights=False,
|
|
144
|
+
)
|
|
145
|
+
else:
|
|
146
|
+
try:
|
|
147
|
+
attn_out, _ = self.self_attn(
|
|
148
|
+
x, x, x,
|
|
149
|
+
attn_mask=attn_mask,
|
|
150
|
+
key_padding_mask=key_padding_mask,
|
|
151
|
+
need_weights=False,
|
|
152
|
+
is_causal=is_causal,
|
|
153
|
+
)
|
|
154
|
+
except TypeError:
|
|
155
|
+
attn_out, _ = self.self_attn(
|
|
156
|
+
x, x, x,
|
|
157
|
+
attn_mask=attn_mask,
|
|
158
|
+
key_padding_mask=key_padding_mask,
|
|
159
|
+
need_weights=False,
|
|
160
|
+
)
|
|
134
161
|
return self.res_scale_attn * self.dropout1(attn_out)
|
|
135
162
|
|
|
136
163
|
def _ff_block(self, x):
|
|
@@ -313,4 +340,3 @@ class MaskedTabularDataset(Dataset):
|
|
|
313
340
|
None if self.X_cat_true is None else self.X_cat_true[idx],
|
|
314
341
|
None if self.cat_mask is None else self.cat_mask[idx],
|
|
315
342
|
)
|
|
316
|
-
|
ins_pricing/setup.py
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
5
|
import inspect
|
|
6
|
+
import os
|
|
6
7
|
from typing import Any, Optional
|
|
7
8
|
|
|
8
9
|
try:
|
|
@@ -14,6 +15,7 @@ except ImportError: # pragma: no cover - handled by callers
|
|
|
14
15
|
torch = None
|
|
15
16
|
|
|
16
17
|
_SUPPORTS_WEIGHTS_ONLY: Optional[bool] = None
|
|
18
|
+
_DYNAMO_PATCHED = False
|
|
17
19
|
|
|
18
20
|
|
|
19
21
|
def _supports_weights_only() -> bool:
|
|
@@ -43,3 +45,41 @@ def torch_load(
|
|
|
43
45
|
if weights_only is not None and _supports_weights_only():
|
|
44
46
|
return torch.load(path, *args, weights_only=weights_only, **kwargs)
|
|
45
47
|
return torch.load(path, *args, **kwargs)
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def _env_truthy(key: str) -> bool:
|
|
51
|
+
value = os.environ.get(key)
|
|
52
|
+
if value is None:
|
|
53
|
+
return False
|
|
54
|
+
return str(value).strip().lower() in {"1", "true", "yes", "y", "on"}
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def disable_torch_dynamo_if_requested() -> None:
|
|
58
|
+
"""Disable torch._dynamo wrappers when compile is explicitly disabled."""
|
|
59
|
+
global _DYNAMO_PATCHED
|
|
60
|
+
if _DYNAMO_PATCHED or not TORCH_AVAILABLE:
|
|
61
|
+
return
|
|
62
|
+
|
|
63
|
+
if not any(
|
|
64
|
+
_env_truthy(k)
|
|
65
|
+
for k in (
|
|
66
|
+
"TORCHDYNAMO_DISABLE",
|
|
67
|
+
"TORCH_DISABLE_DYNAMO",
|
|
68
|
+
"TORCH_COMPILE_DISABLE",
|
|
69
|
+
"TORCHINDUCTOR_DISABLE",
|
|
70
|
+
)
|
|
71
|
+
):
|
|
72
|
+
return
|
|
73
|
+
|
|
74
|
+
try:
|
|
75
|
+
import torch.optim.optimizer as optim_mod
|
|
76
|
+
except Exception:
|
|
77
|
+
return
|
|
78
|
+
|
|
79
|
+
for name in ("state_dict", "load_state_dict", "zero_grad", "add_param_group"):
|
|
80
|
+
fn = getattr(optim_mod.Optimizer, name, None)
|
|
81
|
+
wrapped = getattr(fn, "__wrapped__", None)
|
|
82
|
+
if wrapped is not None:
|
|
83
|
+
setattr(optim_mod.Optimizer, name, wrapped)
|
|
84
|
+
|
|
85
|
+
_DYNAMO_PATCHED = True
|
|
@@ -3,8 +3,8 @@ ins_pricing/README.md,sha256=W4V2xtzM6pyQzwJPvWP7cNn-We9rxM8xrxRlBVQwoY8,3399
|
|
|
3
3
|
ins_pricing/RELEASE_NOTES_0.2.8.md,sha256=KIJzk1jbZbZPKjwnkPSDHO_2Ipv3SP3CzCNDdf07jI0,9331
|
|
4
4
|
ins_pricing/__init__.py,sha256=46j1wCdLVrgrofeBwKl-3NXTxzjbTv-w3KjW-dyKGiY,2622
|
|
5
5
|
ins_pricing/exceptions.py,sha256=5fZavPV4zNJ7wPC75L215KkHXX9pRrfDAYZOdSKJMGo,4778
|
|
6
|
-
ins_pricing/setup.py,sha256=
|
|
7
|
-
ins_pricing/cli/BayesOpt_entry.py,sha256=
|
|
6
|
+
ins_pricing/setup.py,sha256=Nz6Xi6xRpfAnJ-WWSGRHTxIUiAmb3C9SxktpW_aOf9Y,1702
|
|
7
|
+
ins_pricing/cli/BayesOpt_entry.py,sha256=6UBVxu36O3bXn1WC-BBi-l_W9_MqEoHmDGnwwDKNo5Q,1594
|
|
8
8
|
ins_pricing/cli/BayesOpt_incremental.py,sha256=_Klr5vvNoq_TbgwrH_T3f0a6cHmA9iVJMViiji6ahJY,35927
|
|
9
9
|
ins_pricing/cli/Explain_Run.py,sha256=gEPQjqHiXyXlCTKjUzwSvbAn5_h74ABgb_sEGs-YHVE,664
|
|
10
10
|
ins_pricing/cli/Explain_entry.py,sha256=xS23x31qRvXqy2Wvo21wbkxmPRLHy77aZbtjY-J59NA,23570
|
|
@@ -16,8 +16,8 @@ ins_pricing/cli/utils/__init__.py,sha256=u3kt1B27OiuOEgw6PQN-fNs9vNiAjdPyybsRQsZ
|
|
|
16
16
|
ins_pricing/cli/utils/cli_common.py,sha256=CgMnN_0NQQt7Bh5RjClOydz0LzU2TBmIOsFa3KxYQOQ,8254
|
|
17
17
|
ins_pricing/cli/utils/cli_config.py,sha256=TC8fR1XdQIbaojbeac7dESj7TmCKSfpZTbLvJrkJLEY,13247
|
|
18
18
|
ins_pricing/cli/utils/evaluation_context.py,sha256=0zuDOcVzkWiuj4HyAT0psaAfEbSqpDXEGXSjxztHY6E,9485
|
|
19
|
-
ins_pricing/cli/utils/import_resolver.py,sha256
|
|
20
|
-
ins_pricing/cli/utils/notebook_utils.py,sha256=
|
|
19
|
+
ins_pricing/cli/utils/import_resolver.py,sha256=Ut-SBN4F2sw8O7B3GveMoZn4__1IGwljvxC4sLU0tpk,12531
|
|
20
|
+
ins_pricing/cli/utils/notebook_utils.py,sha256=xjSjn6z4_x2vfX1SV4X_VG0jXdK1KJzWJ5tJ4CHFxy0,12037
|
|
21
21
|
ins_pricing/cli/utils/run_logging.py,sha256=V3Wh2EV6c1Mo0QTvfe4hl2J4LOR6bdQsT210o__YBWk,3677
|
|
22
22
|
ins_pricing/docs/modelling/BayesOpt_USAGE.md,sha256=kPhaIhRSS4SkbIYjaJ1f3dVfXWqNIWKi0BgUU5QQEqc,40560
|
|
23
23
|
ins_pricing/docs/modelling/README.md,sha256=2a7m1dBnacxBKjEV9k16Qj9IPstlwwuis1QxdsMrFmA,1976
|
|
@@ -34,7 +34,7 @@ ins_pricing/modelling/core/evaluation.py,sha256=wEMWdzs12vPnDo5t183ORMDA6APuc5g6
|
|
|
34
34
|
ins_pricing/modelling/core/bayesopt/PHASE2_REFACTORING_SUMMARY.md,sha256=x8890HLvIZ7q2N0AdYwL1_8lBUl6vClZ9SoEj-BskuQ,11835
|
|
35
35
|
ins_pricing/modelling/core/bayesopt/PHASE3_REFACTORING_SUMMARY.md,sha256=B8ZEzaLesU454OaR10Tg50es7t30UB9pxF6GabbNbj0,11804
|
|
36
36
|
ins_pricing/modelling/core/bayesopt/REFACTORING_SUMMARY.md,sha256=hJZKXe9-bBGJVN_5c5l8nHQ1X7NK4BbeE-uXQoH0rAM,7479
|
|
37
|
-
ins_pricing/modelling/core/bayesopt/__init__.py,sha256=
|
|
37
|
+
ins_pricing/modelling/core/bayesopt/__init__.py,sha256=nj6IA0r7D5U5-hYyiwXmcp_bEtoU-hRJ_prdtRmLMg0,2070
|
|
38
38
|
ins_pricing/modelling/core/bayesopt/config_components.py,sha256=OjRyM1EuSXL9_3THD1nGLRsioJs7lO_ZKVZDkUA3LX8,12156
|
|
39
39
|
ins_pricing/modelling/core/bayesopt/config_preprocess.py,sha256=5oFbesUPiTeqEVY_j6c9Ake_7K9CWcwSutcUWo6EuxY,20665
|
|
40
40
|
ins_pricing/modelling/core/bayesopt/core.py,sha256=tRgCso6--QL-Orj8oFqLgsFj6wV5bR5Rx21iffKNWVY,43873
|
|
@@ -43,7 +43,7 @@ ins_pricing/modelling/core/bayesopt/model_plotting_mixin.py,sha256=lD0rUvWV4eWat
|
|
|
43
43
|
ins_pricing/modelling/core/bayesopt/utils.py,sha256=fTDqBHCxsOVte0QhPqnMw8vkefIvkppufIRkt9iHqjU,2852
|
|
44
44
|
ins_pricing/modelling/core/bayesopt/utils_backup.py,sha256=5RKizpR3j6KwR87WqqaXPtgjQXWPW4vM75sIkx38SSM,57924
|
|
45
45
|
ins_pricing/modelling/core/bayesopt/models/__init__.py,sha256=vFFCkGnO6rm50TbxR6QekKKQjq-NW4UFwog6fng8-p8,700
|
|
46
|
-
ins_pricing/modelling/core/bayesopt/models/model_ft_components.py,sha256=
|
|
46
|
+
ins_pricing/modelling/core/bayesopt/models/model_ft_components.py,sha256=oDhmJQ26zF0PhoDC5Z2McA-JpLbXFQjSREqy0w_hWlQ,11883
|
|
47
47
|
ins_pricing/modelling/core/bayesopt/models/model_ft_trainer.py,sha256=srBsI4KmijRC6s4G-XlVI9ahzjc2yquQxgdeICP1_4A,39253
|
|
48
48
|
ins_pricing/modelling/core/bayesopt/models/model_gnn.py,sha256=1LdcuMwCRXsQcdj1Xjm8NlLjpX-cmunJlelkc2pfGB4,32400
|
|
49
49
|
ins_pricing/modelling/core/bayesopt/models/model_resn.py,sha256=hAU77GcGC1mHbOOLfZ9vC5nhUhHlaPZmXjrkH3BrjKc,17128
|
|
@@ -118,9 +118,9 @@ ins_pricing/utils/logging.py,sha256=_AKB4ErmvygwGLtu7Ai7ESemj6Hh8FTgh4cs8j_gVW4,
|
|
|
118
118
|
ins_pricing/utils/metrics.py,sha256=zhKYgXgki8RDscjP_GO2lEgzrtMIZCqOX_aLpQzdw6k,8390
|
|
119
119
|
ins_pricing/utils/paths.py,sha256=o_tBiclFvBci4cYg9WANwKPxrMcglEdOjDP-EZgGjdQ,8749
|
|
120
120
|
ins_pricing/utils/profiling.py,sha256=kmbykHLcYywlZxAf_aVU8HXID3zOvUcBoO5Q58AijhA,11132
|
|
121
|
-
ins_pricing/utils/torch_compat.py,sha256=
|
|
121
|
+
ins_pricing/utils/torch_compat.py,sha256=UrRsqx2qboDG8WE0OmxNOi08ojwE-dCxTQh0N2s3Rgw,2441
|
|
122
122
|
ins_pricing/utils/validation.py,sha256=4Tw9VUJPk0N-WO3YUqZP-xXRl1Xpubkm0vi3WzzZrv4,13348
|
|
123
|
-
ins_pricing-0.3.
|
|
124
|
-
ins_pricing-0.3.
|
|
125
|
-
ins_pricing-0.3.
|
|
126
|
-
ins_pricing-0.3.
|
|
123
|
+
ins_pricing-0.3.3.dist-info/METADATA,sha256=E1pjWhoOdv2Iwm-A_Aordv_gRyCkH5UB9fbPZyzxNh0,6101
|
|
124
|
+
ins_pricing-0.3.3.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
125
|
+
ins_pricing-0.3.3.dist-info/top_level.txt,sha256=haZuNQpHKNBEPZx3NjLnHp8pV3I_J9QG8-HyJn00FA0,12
|
|
126
|
+
ins_pricing-0.3.3.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|