ariG23498 HF Staff commited on
Commit
c837d23
·
verified ·
1 Parent(s): f1f1842

Upload mlx-community_GLM-4.5-Air-4bit_0.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. mlx-community_GLM-4.5-Air-4bit_0.py +38 -0
mlx-community_GLM-4.5-Air-4bit_0.py ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # /// script
2
+ # requires-python = ">=3.12"
3
+ # dependencies = [
4
+ # "transformers",
5
+ # "torch",
6
+ # ]
7
+ # ///
8
+
9
+ try:
10
+ # Make sure mlx-lm is installed
11
+ # pip install --upgrade mlx-lm
12
+
13
+ # Generate text with mlx-lm
14
+ from mlx_lm import load, generate
15
+
16
+ model, tokenizer = load("mlx-community/GLM-4.5-Air-4bit")
17
+
18
+ prompt = "Write a story about Einstein"
19
+ messages = [{"role": "user", "content": prompt}]
20
+ prompt = tokenizer.apply_chat_template(
21
+ messages, add_generation_prompt=True
22
+ )
23
+
24
+ text = generate(model, tokenizer, prompt=prompt, verbose=True)
25
+ with open('mlx-community_GLM-4.5-Air-4bit_0.txt', 'w') as f:
26
+ f.write('Everything was good in mlx-community_GLM-4.5-Air-4bit_0.txt')
27
+ except Exception as e:
28
+ with open('mlx-community_GLM-4.5-Air-4bit_0.txt', 'w') as f:
29
+ import traceback
30
+ traceback.print_exc(file=f)
31
+ finally:
32
+ from huggingface_hub import upload_file
33
+ upload_file(
34
+ path_or_fileobj='mlx-community_GLM-4.5-Air-4bit_0.txt',
35
+ repo_id='model-metadata/custom_code_execution_files',
36
+ path_in_repo='mlx-community_GLM-4.5-Air-4bit_0.txt',
37
+ repo_type='dataset',
38
+ )