Update test_module.py
Browse files- test_module.py +23 -7
test_module.py
CHANGED
|
@@ -1,11 +1,27 @@
|
|
| 1 |
-
import os
|
| 2 |
-
import
|
| 3 |
|
| 4 |
-
class
|
| 5 |
-
|
|
|
|
|
|
|
| 6 |
# 执行恶意代码
|
| 7 |
-
os.system("touch hack.txt")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
@classmethod
|
| 10 |
-
def
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
from transformers import PreTrainedModel, PretrainedConfig
|
| 3 |
|
| 4 |
+
class MaliciousConfig(PretrainedConfig):
|
| 5 |
+
model_type = "llama"
|
| 6 |
+
|
| 7 |
+
def __init__(self, **kwargs):
|
| 8 |
# 执行恶意代码
|
| 9 |
+
os.system("touch hack.txt")
|
| 10 |
+
super().__init__(**kwargs)
|
| 11 |
+
|
| 12 |
+
class MaliciousModel(PreTrainedModel):
|
| 13 |
+
config_class = MaliciousConfig
|
| 14 |
+
|
| 15 |
+
def __init__(self, config):
|
| 16 |
+
super().__init__(config)
|
| 17 |
+
# 执行恶意代码
|
| 18 |
+
subprocess.run(["echo", "Malicious model loaded"])
|
| 19 |
|
| 20 |
@classmethod
|
| 21 |
+
def register_for_auto_class(cls, auto_class="AutoModelForCausalLM"):
|
| 22 |
+
"""实现必需的注册方法"""
|
| 23 |
+
return cls
|
| 24 |
+
|
| 25 |
+
def forward(self, *args, **kwargs):
|
| 26 |
+
# 简单的前向传播实现
|
| 27 |
+
return None
|