File size: 1,379 Bytes
22741d9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python3
"""Hotpatch the stale Space image before training runs."""
import os, sys, shutil

# Patch model.py to use getattr for retina_contrastive
p = "/workspace/feather/hydra/model.py"
txt = open(p).read()
old = "self.sdr_semantic.retina_contrastive is not None"
new = "getattr(self.sdr_semantic, 'retina_contrastive', None) is not None"
if old in txt:
    txt = txt.replace(old, new)
    open(p, "w").write(txt)
    print("[hotpatch] retina_contrastive guard patched")
else:
    print("[hotpatch] retina_contrastive guard already present or ref changed")

# Also patch sdr_semantic.py to ensure retina_contrastive always exists
sp = "/workspace/feather/subsystems/sdr_semantic.py"
stxt = open(sp).read()
# The conditional init has it, but the stale image may have a version without the fallback
# Add a safety fallback at the end of __init__
fallback = """
        # Hotpatch safety: ensure retina_contrastive always exists
        if not hasattr(self, 'retina_contrastive'):
            self.retina_contrastive = None
"""
if "Hotpatch safety" not in stxt:
    stxt = stxt.replace("self._som_step: int = 0", "self._som_step: int = 0" + fallback)
    open(sp, "w").write(stxt)
    print("[hotpatch] sdr_semantic retina_contrastive safety added")
else:
    print("[hotpatch] safety already present")

os.execl(sys.executable, sys.executable, "/app/entrypoint.py")