derek-thomas commited on
Commit
bf52501
·
verified ·
1 Parent(s): 3951475

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -10
app.py CHANGED
@@ -7,7 +7,7 @@ def get_hf_model_args(hf_model_name_or_path):
7
  try:
8
  config = AutoConfig.from_pretrained(hf_model_name_or_path, trust_remote_code=True).to_dict()
9
  except Exception as e:
10
- return None, f"Error fetching Hugging Face model: {str(e)}"
11
 
12
  # Extract relevant values from the config
13
  num_layers = config.get("num_hidden_layers", None)
@@ -22,14 +22,11 @@ def get_hf_model_args(hf_model_name_or_path):
22
  "num_attention_heads": num_attention_heads,
23
  "vocab_size": vocab_size,
24
  "sequence_length": sequence_length,
25
- }, None
26
 
27
  # ---- Update Gradio inputs with Hugging Face model config ---- #
28
  def update_from_hf_model(hf_model_name_or_path):
29
- model_params, hf_error = get_hf_model_args(hf_model_name_or_path)
30
-
31
- if hf_error:
32
- return gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), hf_error
33
 
34
  return (gr.update(value=model_params["num_layers"]),
35
  gr.update(value=model_params["hidden_size"]),
@@ -40,10 +37,7 @@ def update_from_hf_model(hf_model_name_or_path):
40
 
41
  # ---- Memory Calculation ---- #
42
  def calc_mem(hf_model_name_or_path, num_gpus, tensor_parallel_size, pipeline_parallel_size, batch_size_per_gpu, sequence_length, vocab_size, hidden_size, num_attention_heads, num_layers, ffn_expansion_factor, is_mixed_precision, misc_mem_gib):
43
- model_params, hf_error = get_hf_model_args(hf_model_name_or_path) if hf_model_name_or_path else (None, None)
44
-
45
- if hf_error:
46
- return hf_error
47
 
48
  if model_params:
49
  num_layers = model_params["num_layers"] or num_layers
 
7
  try:
8
  config = AutoConfig.from_pretrained(hf_model_name_or_path, trust_remote_code=True).to_dict()
9
  except Exception as e:
10
+ raise gr.Error(f"Error fetching Hugging Face model: {str(e)}")
11
 
12
  # Extract relevant values from the config
13
  num_layers = config.get("num_hidden_layers", None)
 
22
  "num_attention_heads": num_attention_heads,
23
  "vocab_size": vocab_size,
24
  "sequence_length": sequence_length,
25
+ }
26
 
27
  # ---- Update Gradio inputs with Hugging Face model config ---- #
28
  def update_from_hf_model(hf_model_name_or_path):
29
+ model_params = get_hf_model_args(hf_model_name_or_path)
 
 
 
30
 
31
  return (gr.update(value=model_params["num_layers"]),
32
  gr.update(value=model_params["hidden_size"]),
 
37
 
38
  # ---- Memory Calculation ---- #
39
  def calc_mem(hf_model_name_or_path, num_gpus, tensor_parallel_size, pipeline_parallel_size, batch_size_per_gpu, sequence_length, vocab_size, hidden_size, num_attention_heads, num_layers, ffn_expansion_factor, is_mixed_precision, misc_mem_gib):
40
+ model_params = get_hf_model_args(hf_model_name_or_path) if hf_model_name_or_path else None
 
 
 
41
 
42
  if model_params:
43
  num_layers = model_params["num_layers"] or num_layers