forked from google-deepmind/recurrentgemma
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpatch_rg.py
More file actions
executable file
·63 lines (48 loc) · 1.88 KB
/
Copy pathpatch_rg.py
File metadata and controls
executable file
·63 lines (48 loc) · 1.88 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import os
import re
def patch_file(filepath):
try:
with open(filepath, "r") as f:
content = f.read()
original_content = content
# 1. Strip out all @at.typed decorators
# Using a regex that handles potential whitespace
content = re.sub(r"^\s*@at\.typed\s*\n", "", content, flags=re.MULTILINE)
# 2. Specifically target the array_typing.py to disable the decorator source
if filepath.endswith("array_typing.py"):
# Replace the active decorator with a dummy passthrough
dummy_decorator = """
def typed(function):
\"\"\"Dummy passthrough for Python 3.12 compatibility.\"\"\"
return function
"""
# Replace the jaxtyped import and definition
content = re.sub(
r"def typed\(function\).*?return jt\.jaxtyped.*?typechecked\)",
dummy_decorator.strip(),
content,
flags=re.DOTALL,
)
if content != original_content:
with open(filepath, "w") as f:
f.write(content)
print(f"Patched: {filepath}")
except Exception as e:
print(f"Error patching {filepath}: {e}")
def main():
print("--- Booting RecurrentGemma AST Patcher (Python 3.12) ---")
# Path to the specific folder you are using
base_dir = "/workspace/recurrentgemma/recurrentgemma/jax"
if not os.path.exists(base_dir):
print(f"Directory not found: {base_dir}")
print("Please verify the path to the recurrentgemma/jax folder.")
return
# Walk through all python files in the jax directory
for root, _, files in os.walk(base_dir):
for file in files:
if file.endswith(".py"):
filepath = os.path.join(root, file)
patch_file(filepath)
print("--- Patching Complete ---")
if __name__ == "__main__":
main()