ariG23498 HF Staff commited on
Commit
5441abd
·
verified ·
1 Parent(s): 5b1b733

Upload Qwen_Qwen3-4B-Instruct-2507_1.py with huggingface_hub

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