hacnho commited on
Commit
01b0979
·
verified ·
1 Parent(s): 09cee7e

Upload build_poc.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. build_poc.py +43 -0
build_poc.py ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ from __future__ import annotations
3
+
4
+ import hashlib
5
+ import json
6
+ from pathlib import Path
7
+
8
+ import msgspec
9
+
10
+
11
+ ROOT = Path(__file__).resolve().parent
12
+ ARTIFACTS = ROOT / "artifacts"
13
+ CONTROL = ARTIFACTS / "control.msgpack"
14
+ MALICIOUS = ARTIFACTS / "decoder_trigger.msgpack"
15
+
16
+
17
+ def sha256(path: Path) -> str:
18
+ return hashlib.sha256(path.read_bytes()).hexdigest()
19
+
20
+
21
+ def main() -> None:
22
+ manifest = {
23
+ "format": "MessagePack (.msgpack)",
24
+ "loader": "msgspec.msgpack.Decoder(type=ModelState).decode",
25
+ "msgspec_version": msgspec.__version__,
26
+ "control": {
27
+ "path": str(CONTROL),
28
+ "size": CONTROL.stat().st_size,
29
+ "sha256": sha256(CONTROL),
30
+ },
31
+ "malicious": {
32
+ "path": str(MALICIOUS),
33
+ "size": MALICIOUS.stat().st_size,
34
+ "sha256": sha256(MALICIOUS),
35
+ },
36
+ "trigger_vector": [4, 2, 7],
37
+ }
38
+ (ARTIFACTS / "manifest.json").write_text(json.dumps(manifest, indent=2) + "\n", encoding="utf-8")
39
+ print(json.dumps(manifest, indent=2))
40
+
41
+
42
+ if __name__ == "__main__":
43
+ main()