MCPcopy Create free account
hub / github.com/BICLab/SpikingBrain-7B / patch_fla_bitnet

Function patch_fla_bitnet

docker_build/patch_fla_bitnet.py:12–62  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

10
11
12def patch_fla_bitnet():
13
14
15 # 尝试在系统Python路径中查找
16 import site
17 for package_path in site.getsitepackages():
18 potential_path = os.path.join(package_path, 'fla', 'models', 'bitnet', '__init__.py')
19 if os.path.exists(potential_path):
20 print(f'Found path: {potential_path}')
21
22 with open(potential_path, 'r') as f:
23 content = f.read()
24
25 # 检查是否已经修改过
26 if 'exist_ok=True' in content:
27 print('File already patched')
28 return True
29
30 # 进行替换
31 # content = content.replace(
32 # 'AutoConfig.register(ABCConfig.model_type, ABCConfig)',
33 # 'AutoConfig.register(ABCConfig.model_type, ABCConfig, exist_ok=True)'
34 # )
35 # content = content.replace(
36 # 'AutoModel.register(ABCConfig, ABCModel)',
37 # 'AutoModel.register(ABCConfig, ABCModel, exist_ok=True)'
38 # )
39 # content = content.replace(
40 # 'AutoModelForCausalLM.register(ABCConfig, ABCForCausalLM)',
41 # 'AutoModelForCausalLM.register(ABCConfig, ABCForCausalLM, exist_ok=True)'
42 # )
43 content = content.replace(
44 "AutoConfig.register(BitNetConfig.model_type, BitNetConfig)",
45 "AutoConfig.register(BitNetConfig.model_type, BitNetConfig, exist_ok=True)"
46 )
47 content = content.replace(
48 "AutoModel.register(BitNetConfig, BitNetModel)",
49 "AutoModel.register(BitNetConfig, BitNetModel, exist_ok=True)",
50 )
51 content = content.replace(
52 "AutoModelForCausalLM.register(BitNetConfig, BitNetForCausalLM)",
53 "AutoModelForCausalLM.register(BitNetConfig, BitNetForCausalLM, exist_ok=True)",
54 )
55 with open(potential_path, 'w') as f:
56 f.write(content)
57
58 print('Successfully modified alternative path')
59 return True
60
61 print('Error: Could not find flash-linear-attention installation')
62 return False
63
64
65if __name__ == '__main__':

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected