code-loader 1.0.217__tar.gz → 1.0.218__tar.gz
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.
- {code_loader-1.0.217 → code_loader-1.0.218}/PKG-INFO +1 -1
- {code_loader-1.0.217 → code_loader-1.0.218}/code_loader/inner_leap_binder/leapbinder.py +0 -1
- {code_loader-1.0.217 → code_loader-1.0.218}/code_loader/inner_leap_binder/leapbinder_decorators.py +36 -18
- {code_loader-1.0.217 → code_loader-1.0.218}/code_loader/mixpanel_tracker.py +81 -1
- {code_loader-1.0.217 → code_loader-1.0.218}/pyproject.toml +1 -1
- {code_loader-1.0.217 → code_loader-1.0.218}/LICENSE +0 -0
- {code_loader-1.0.217 → code_loader-1.0.218}/README.md +0 -0
- {code_loader-1.0.217 → code_loader-1.0.218}/code_loader/__init__.py +0 -0
- {code_loader-1.0.217 → code_loader-1.0.218}/code_loader/contract/__init__.py +0 -0
- {code_loader-1.0.217 → code_loader-1.0.218}/code_loader/contract/datasetclasses.py +0 -0
- {code_loader-1.0.217 → code_loader-1.0.218}/code_loader/contract/enums.py +0 -0
- {code_loader-1.0.217 → code_loader-1.0.218}/code_loader/contract/exceptions.py +0 -0
- {code_loader-1.0.217 → code_loader-1.0.218}/code_loader/contract/mapping.py +0 -0
- {code_loader-1.0.217 → code_loader-1.0.218}/code_loader/contract/responsedataclasses.py +0 -0
- {code_loader-1.0.217 → code_loader-1.0.218}/code_loader/contract/sim_config.py +0 -0
- {code_loader-1.0.217 → code_loader-1.0.218}/code_loader/contract/visualizer_classes.py +0 -0
- {code_loader-1.0.217 → code_loader-1.0.218}/code_loader/default_losses.py +0 -0
- {code_loader-1.0.217 → code_loader-1.0.218}/code_loader/default_metrics.py +0 -0
- {code_loader-1.0.217 → code_loader-1.0.218}/code_loader/experiment_api/__init__.py +0 -0
- {code_loader-1.0.217 → code_loader-1.0.218}/code_loader/experiment_api/api.py +0 -0
- {code_loader-1.0.217 → code_loader-1.0.218}/code_loader/experiment_api/cli_config_utils.py +0 -0
- {code_loader-1.0.217 → code_loader-1.0.218}/code_loader/experiment_api/client.py +0 -0
- {code_loader-1.0.217 → code_loader-1.0.218}/code_loader/experiment_api/epoch.py +0 -0
- {code_loader-1.0.217 → code_loader-1.0.218}/code_loader/experiment_api/experiment.py +0 -0
- {code_loader-1.0.217 → code_loader-1.0.218}/code_loader/experiment_api/experiment_context.py +0 -0
- {code_loader-1.0.217 → code_loader-1.0.218}/code_loader/experiment_api/types.py +0 -0
- {code_loader-1.0.217 → code_loader-1.0.218}/code_loader/experiment_api/utils.py +0 -0
- {code_loader-1.0.217 → code_loader-1.0.218}/code_loader/experiment_api/workingspace_config_utils.py +0 -0
- {code_loader-1.0.217 → code_loader-1.0.218}/code_loader/inner_leap_binder/__init__.py +0 -0
- {code_loader-1.0.217 → code_loader-1.0.218}/code_loader/leaploader.py +0 -0
- {code_loader-1.0.217 → code_loader-1.0.218}/code_loader/leaploaderbase.py +0 -0
- {code_loader-1.0.217 → code_loader-1.0.218}/code_loader/plot_functions/__init__.py +0 -0
- {code_loader-1.0.217 → code_loader-1.0.218}/code_loader/plot_functions/plot_functions.py +0 -0
- {code_loader-1.0.217 → code_loader-1.0.218}/code_loader/plot_functions/visualize.py +0 -0
- {code_loader-1.0.217 → code_loader-1.0.218}/code_loader/utils.py +0 -0
- {code_loader-1.0.217 → code_loader-1.0.218}/code_loader/visualizers/__init__.py +0 -0
- {code_loader-1.0.217 → code_loader-1.0.218}/code_loader/visualizers/default_visualizers.py +0 -0
|
@@ -1134,7 +1134,6 @@ class LeapBinder:
|
|
|
1134
1134
|
self.check_simulations()
|
|
1135
1135
|
self.validate_ignore_latent_spaces()
|
|
1136
1136
|
self.validate_use_additional_set_as_unlabeled_candidate()
|
|
1137
|
-
print("Successful!")
|
|
1138
1137
|
|
|
1139
1138
|
def validate_autoregressive_setup(self) -> None:
|
|
1140
1139
|
"""Structural rules for autoregressive integrations (no-op when the hook is absent).
|
{code_loader-1.0.217 → code_loader-1.0.218}/code_loader/inner_leap_binder/leapbinder_decorators.py
RENAMED
|
@@ -50,6 +50,12 @@ _integration_test_started = False
|
|
|
50
50
|
_mapping_dataset_is_grouped = False
|
|
51
51
|
_call_from_tl_platform = os.environ.get('IS_TENSORLEAP_PLATFORM') == 'true'
|
|
52
52
|
|
|
53
|
+
# Verdicts of the local status table, and the exit status of a run that was clean but left a
|
|
54
|
+
# mandatory part out of the integration test (0 = ready to push, 1 = crash, as Python reports it).
|
|
55
|
+
INTEGRATION_READY = "ready"
|
|
56
|
+
INTEGRATION_INCOMPLETE = "incomplete"
|
|
57
|
+
EXIT_CODE_INTEGRATION_INCOMPLETE = 3
|
|
58
|
+
|
|
53
59
|
# ---- warnings store (module-level) ----
|
|
54
60
|
_UNSET = object()
|
|
55
61
|
_STORED_WARNINGS: List[Dict[str, Any]] = []
|
|
@@ -4188,9 +4194,6 @@ def tensorleap_status_table():
|
|
|
4188
4194
|
# printed, gate readiness, or be recommended as a next step.
|
|
4189
4195
|
table[:] = [row for row in table if row["name"] != "tensorleap_input_encoder"]
|
|
4190
4196
|
|
|
4191
|
-
ready_mess = "\nAll parts have been successfully set. If no errors accured, you can now push the project to the Tensorleap system."
|
|
4192
|
-
not_ready_mess = "\nSome mandatory components have not yet been added to the Integration test. Recommended next interface to add is: "
|
|
4193
|
-
mandatory_ready_mess = "\nAll mandatory parts have been successfully set. If no errors accured, you can now push the project to the Tensorleap system or continue to the next optional reccomeded interface,adding: "
|
|
4194
4197
|
code_mapping_failure_mes = "Tensorleap_integration_test code flow failed, check raised exception."
|
|
4195
4198
|
|
|
4196
4199
|
name_width = max(len(row["name"]) for row in table)
|
|
@@ -4205,18 +4208,9 @@ def tensorleap_status_table():
|
|
|
4205
4208
|
for row in table:
|
|
4206
4209
|
print(f"{row['name'].ljust(name_width)} | {row['Added to integration'].ljust(status_width)}")
|
|
4207
4210
|
|
|
4208
|
-
# Determine next_step based on original table order (recommended integration order)
|
|
4209
|
-
ready = True
|
|
4210
|
-
next_step = None
|
|
4211
|
-
for row in table:
|
|
4212
|
-
if not _crashed["value"] and ready:
|
|
4213
|
-
if row["Added to integration"] != CHECK:
|
|
4214
|
-
ready = False
|
|
4215
|
-
next_step = row["name"]
|
|
4216
|
-
|
|
4217
4211
|
if code_mapping_failure[0]:
|
|
4218
4212
|
print(f"\n{CROSS} {code_mapping_failure_mes}")
|
|
4219
|
-
return
|
|
4213
|
+
return None
|
|
4220
4214
|
|
|
4221
4215
|
if _crashed["value"]:
|
|
4222
4216
|
crashed_at = _current_func['name']
|
|
@@ -4224,11 +4218,24 @@ def tensorleap_status_table():
|
|
|
4224
4218
|
print(f"\nScript crashed before completing all steps. crashed at function '{crashed_at}'.")
|
|
4225
4219
|
else:
|
|
4226
4220
|
print("\nScript crashed before completing all steps.")
|
|
4227
|
-
return
|
|
4221
|
+
return None
|
|
4228
4222
|
|
|
4229
|
-
|
|
4230
|
-
|
|
4231
|
-
)
|
|
4223
|
+
# The next step follows the table order (the recommended integration order), but every
|
|
4224
|
+
# mandatory row comes before any optional one: rows appended at registration time (e.g. the
|
|
4225
|
+
# autoregressive step) sit after the optional rows and must still gate readiness.
|
|
4226
|
+
missing = [row["name"] for row in table if row["Added to integration"] != CHECK]
|
|
4227
|
+
missing_mandatory = [name for name in missing if "optional" not in name]
|
|
4228
|
+
if missing_mandatory:
|
|
4229
|
+
next_step = missing_mandatory[0]
|
|
4230
|
+
what = "has not run yet" if next_step == "tensorleap_integration_test" \
|
|
4231
|
+
else "is not used in the integration test yet"
|
|
4232
|
+
print(f"\nThis integration is not ready to push: `{next_step}` {what}. Add it next.")
|
|
4233
|
+
return INTEGRATION_INCOMPLETE
|
|
4234
|
+
|
|
4235
|
+
print("\nReady to push: all mandatory parts are in the integration test.")
|
|
4236
|
+
if missing:
|
|
4237
|
+
print(f"Optional next: `{_remove_suffix(missing[0], ' (optional)')}`.")
|
|
4238
|
+
return INTEGRATION_READY
|
|
4232
4239
|
|
|
4233
4240
|
def set_current(name: str):
|
|
4234
4241
|
_current_func["name"] = name
|
|
@@ -4289,7 +4296,18 @@ def tensorleap_status_table():
|
|
|
4289
4296
|
_mark_unknowns_as_cross()
|
|
4290
4297
|
_resolve_sim_row()
|
|
4291
4298
|
|
|
4292
|
-
_print_table()
|
|
4299
|
+
verdict = _print_table()
|
|
4300
|
+
if verdict == INTEGRATION_INCOMPLETE and not _crashed["value"]:
|
|
4301
|
+
# A clean run that leaves a mandatory row unexercised must not exit 0: helpers and
|
|
4302
|
+
# scripts read exit 0 as "ready to push". An atexit handler cannot change the exit
|
|
4303
|
+
# status with sys.exit (Python ignores SystemExit there), so flush and leave directly.
|
|
4304
|
+
# Exit handlers registered before code-loader was imported are skipped; logging, the
|
|
4305
|
+
# one that matters, is shut down explicitly.
|
|
4306
|
+
import logging
|
|
4307
|
+
sys.stdout.flush()
|
|
4308
|
+
sys.stderr.flush()
|
|
4309
|
+
logging.shutdown()
|
|
4310
|
+
os._exit(EXIT_CODE_INTEGRATION_INCOMPLETE)
|
|
4293
4311
|
|
|
4294
4312
|
def handle_exception(exc_type, exc_value, exc_traceback):
|
|
4295
4313
|
_crashed["value"] = True
|
|
@@ -7,8 +7,10 @@ import getpass
|
|
|
7
7
|
import uuid
|
|
8
8
|
import logging
|
|
9
9
|
from enum import Enum
|
|
10
|
+
from pathlib import Path
|
|
10
11
|
from typing import Optional, Dict, Any, Set, Union, TypedDict
|
|
11
12
|
import mixpanel # type: ignore[import]
|
|
13
|
+
import requests
|
|
12
14
|
|
|
13
15
|
logger = logging.getLogger(__name__)
|
|
14
16
|
|
|
@@ -17,6 +19,17 @@ TL_DISABLE_ANALYTICS_ENV_VAR = 'TL_DISABLE_ANALYTICS'
|
|
|
17
19
|
# Every code-loader event is sent under this one name; `event_type` says which one it is.
|
|
18
20
|
CODE_LOADER_EVENT_NAME = 'code_loader_event'
|
|
19
21
|
|
|
22
|
+
# Events that could not be sent (no network, e.g. inside an AI assistant's sandbox) are appended to
|
|
23
|
+
# <dir containing leap.yaml>/.tensorleap/pending_events.jsonl; leap-cli sends them on the next `leap push`.
|
|
24
|
+
# Each line is exactly the JSON message the Mixpanel consumer would have POSTed to /track.
|
|
25
|
+
PENDING_EVENTS_DIR_NAME = '.tensorleap'
|
|
26
|
+
PENDING_EVENTS_FILE_NAME = 'pending_events.jsonl'
|
|
27
|
+
MAX_PENDING_EVENTS = 1000
|
|
28
|
+
MAX_PENDING_EVENTS_BYTES = 1024 * 1024
|
|
29
|
+
# Set after the first send that fails for lack of network: later events in this process are buffered
|
|
30
|
+
# without trying, since each failed try costs a few seconds of retries.
|
|
31
|
+
_mixpanel_unreachable = False
|
|
32
|
+
|
|
20
33
|
|
|
21
34
|
class AnalyticsEvent(str, Enum):
|
|
22
35
|
"""Enumeration of all tracked analytics events, sent as the `event_type` of a code_loader_event."""
|
|
@@ -56,12 +69,79 @@ class GtEncoderEventProps(TypedDict, total=False):
|
|
|
56
69
|
encoder_name: str
|
|
57
70
|
|
|
58
71
|
|
|
72
|
+
def _find_project_dir() -> Optional[Path]:
|
|
73
|
+
"""The directory holding leap.yaml: searched up from the working directory, then from the entry script."""
|
|
74
|
+
import __main__
|
|
75
|
+
start_dirs = [Path.cwd()]
|
|
76
|
+
main_file = getattr(__main__, '__file__', None)
|
|
77
|
+
if main_file:
|
|
78
|
+
start_dirs.append(Path(main_file).resolve().parent)
|
|
79
|
+
for start_dir in start_dirs:
|
|
80
|
+
for candidate in [start_dir, *start_dir.parents]:
|
|
81
|
+
if (candidate / 'leap.yaml').is_file():
|
|
82
|
+
return candidate
|
|
83
|
+
return None
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
def _append_pending_event(json_message: str) -> None:
|
|
87
|
+
"""Append an unsent Mixpanel message to the project's pending-events file. Never raises."""
|
|
88
|
+
try:
|
|
89
|
+
project_dir = _find_project_dir()
|
|
90
|
+
if project_dir is None:
|
|
91
|
+
return
|
|
92
|
+
events_dir = project_dir / PENDING_EVENTS_DIR_NAME
|
|
93
|
+
events_dir.mkdir(exist_ok=True)
|
|
94
|
+
gitignore_path = events_dir / '.gitignore'
|
|
95
|
+
if not gitignore_path.exists():
|
|
96
|
+
gitignore_path.write_text('*\n')
|
|
97
|
+
|
|
98
|
+
line = (json_message + '\n').encode('utf-8')
|
|
99
|
+
events_path = events_dir / PENDING_EVENTS_FILE_NAME
|
|
100
|
+
if events_path.exists():
|
|
101
|
+
if events_path.stat().st_size + len(line) > MAX_PENDING_EVENTS_BYTES:
|
|
102
|
+
return
|
|
103
|
+
with open(events_path, 'rb') as f:
|
|
104
|
+
if sum(1 for _ in f) >= MAX_PENDING_EVENTS:
|
|
105
|
+
return
|
|
106
|
+
# One O_APPEND write per line, so a line is never interleaved with another writer's.
|
|
107
|
+
fd = os.open(events_path, os.O_WRONLY | os.O_APPEND | os.O_CREAT, 0o644)
|
|
108
|
+
try:
|
|
109
|
+
os.write(fd, line)
|
|
110
|
+
finally:
|
|
111
|
+
os.close(fd)
|
|
112
|
+
except Exception as e:
|
|
113
|
+
logger.debug(f"Failed to buffer unsent analytics event: {e}")
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
class _BufferingConsumer:
|
|
117
|
+
"""A Mixpanel consumer that buffers an event to disk when it can't reach Mixpanel."""
|
|
118
|
+
|
|
119
|
+
def __init__(self) -> None:
|
|
120
|
+
self._consumer = mixpanel.Consumer()
|
|
121
|
+
|
|
122
|
+
def send(self, endpoint: str, json_message: str, api_key: Optional[str] = None,
|
|
123
|
+
api_secret: Optional[str] = None) -> None:
|
|
124
|
+
global _mixpanel_unreachable
|
|
125
|
+
if endpoint == 'events' and _mixpanel_unreachable:
|
|
126
|
+
_append_pending_event(json_message)
|
|
127
|
+
return
|
|
128
|
+
try:
|
|
129
|
+
self._consumer.send(endpoint, json_message, api_key, api_secret)
|
|
130
|
+
except mixpanel.MixpanelException as e:
|
|
131
|
+
# Network failures arrive as a MixpanelException raised from a requests exception;
|
|
132
|
+
# an event Mixpanel received and rejected has no such cause and is not retried.
|
|
133
|
+
if endpoint == 'events' and isinstance(e.__cause__, requests.exceptions.RequestException):
|
|
134
|
+
_mixpanel_unreachable = True
|
|
135
|
+
_append_pending_event(json_message)
|
|
136
|
+
raise
|
|
137
|
+
|
|
138
|
+
|
|
59
139
|
class MixpanelTracker:
|
|
60
140
|
"""Handles Mixpanel event tracking for code-loader."""
|
|
61
141
|
|
|
62
142
|
def __init__(self, token: str = "0c1710c9656bbfb1056bb46093e23ca1"):
|
|
63
143
|
self.token = token
|
|
64
|
-
self.mp = mixpanel.Mixpanel(token)
|
|
144
|
+
self.mp = mixpanel.Mixpanel(token, consumer=_BufferingConsumer())
|
|
65
145
|
self._user_id: Optional[str] = None
|
|
66
146
|
|
|
67
147
|
def _get_whoami(self) -> str:
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{code_loader-1.0.217 → code_loader-1.0.218}/code_loader/experiment_api/experiment_context.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{code_loader-1.0.217 → code_loader-1.0.218}/code_loader/experiment_api/workingspace_config_utils.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|