ariG23498 HF Staff commited on
Commit
e32e225
·
verified ·
1 Parent(s): b03356b

Upload fdtn-ai_Foundation-Sec-8B-Instruct_1.py with huggingface_hub

Browse files
fdtn-ai_Foundation-Sec-8B-Instruct_1.py ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # /// script
2
+ # requires-python = ">=3.12"
3
+ # dependencies = [
4
+ # "numpy",
5
+ # "einops",
6
+ # "torch",
7
+ # "transformers",
8
+ # "datasets",
9
+ # "accelerate",
10
+ # "timm",
11
+ # ]
12
+ # ///
13
+
14
+ try:
15
+ # Load model directly
16
+ from transformers import AutoTokenizer, AutoModelForCausalLM
17
+
18
+ tokenizer = AutoTokenizer.from_pretrained("fdtn-ai/Foundation-Sec-8B-Instruct")
19
+ model = AutoModelForCausalLM.from_pretrained("fdtn-ai/Foundation-Sec-8B-Instruct")
20
+ messages = [
21
+ {"role": "user", "content": "Who are you?"},
22
+ ]
23
+ inputs = tokenizer.apply_chat_template(
24
+ messages,
25
+ add_generation_prompt=True,
26
+ tokenize=True,
27
+ return_dict=True,
28
+ return_tensors="pt",
29
+ ).to(model.device)
30
+
31
+ outputs = model.generate(**inputs, max_new_tokens=40)
32
+ print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:]))
33
+ with open('fdtn-ai_Foundation-Sec-8B-Instruct_1.txt', 'w') as f:
34
+ f.write('Everything was good in fdtn-ai_Foundation-Sec-8B-Instruct_1.txt')
35
+ except Exception as e:
36
+ with open('fdtn-ai_Foundation-Sec-8B-Instruct_1.txt', 'w') as f:
37
+ import traceback
38
+ traceback.print_exc(file=f)
39
+ finally:
40
+ from huggingface_hub import upload_file
41
+ upload_file(
42
+ path_or_fileobj='fdtn-ai_Foundation-Sec-8B-Instruct_1.txt',
43
+ repo_id='model-metadata/custom_code_execution_files',
44
+ path_in_repo='fdtn-ai_Foundation-Sec-8B-Instruct_1.txt',
45
+ repo_type='dataset',
46
+ )