pcuenq HF staff commited on
Commit
dcd5ecd
1 Parent(s): 2c3ad17

Apply quant method

Browse files
Files changed (1) hide show
  1. app.py +8 -5
app.py CHANGED
@@ -21,6 +21,12 @@ from mlx_lm import convert
21
 
22
  HF_TOKEN = os.environ.get("HF_TOKEN")
23
 
 
 
 
 
 
 
24
  def clear_hf_cache_space():
25
  scan = scan_cache_dir()
26
  to_delete = []
@@ -83,17 +89,14 @@ def process_model(model_id, q_method, oauth_token: gr.OAuthToken | None):
83
  raise ValueError("You must be logged in to use MLX-my-repo")
84
 
85
  model_name = model_id.split('/')[-1]
86
- print(model_name)
87
  username = whoami(oauth_token.token)["name"]
88
- print(username)
89
-
90
  try:
91
- upload_repo = username + "/" + model_name + "-mlx"
92
  print(upload_repo)
93
  with tempfile.TemporaryDirectory(dir="converted") as tmpdir:
94
  # The target dir must not exist
95
  mlx_path = os.path.join(tmpdir, "mlx")
96
- convert(model_id, mlx_path=mlx_path, quantize=True)
97
  print("Conversion done")
98
  upload_to_hub(path=mlx_path, upload_repo=upload_repo, hf_path=model_id, token=oauth_token.token)
99
  print("Upload done")
 
21
 
22
  HF_TOKEN = os.environ.get("HF_TOKEN")
23
 
24
+ # I'm not sure if we need to add more stuff here
25
+ QUANT_PARAMS = {
26
+ "Q4": 4,
27
+ "Q8": 8,
28
+ }
29
+
30
  def clear_hf_cache_space():
31
  scan = scan_cache_dir()
32
  to_delete = []
 
89
  raise ValueError("You must be logged in to use MLX-my-repo")
90
 
91
  model_name = model_id.split('/')[-1]
 
92
  username = whoami(oauth_token.token)["name"]
 
 
93
  try:
94
+ upload_repo = f"{username}/{model_name}-{q_method}-mlx"
95
  print(upload_repo)
96
  with tempfile.TemporaryDirectory(dir="converted") as tmpdir:
97
  # The target dir must not exist
98
  mlx_path = os.path.join(tmpdir, "mlx")
99
+ convert(model_id, mlx_path=mlx_path, quantize=True, q_bits=QUANT_PARAMS[q_method])
100
  print("Conversion done")
101
  upload_to_hub(path=mlx_path, upload_repo=upload_repo, hf_path=model_id, token=oauth_token.token)
102
  print("Upload done")