muellerzr HF staff commited on
Commit
1ef37f4
1 Parent(s): 198d05b
Files changed (1) hide show
  1. app.py +31 -18
app.py CHANGED
@@ -45,26 +45,39 @@ def calculate_memory(model_name:str, library:str, options:list):
45
  "Total Size": dtype_total_size,
46
  "Training using Adam": dtype_training_size
47
  })
48
- return pd.DataFrame(data)
49
- # return f"## {title}\n\n" + markdown_table(data).set_params(
50
- # row_sep="markdown", quote=False,
51
- # ).get_markdown()
52
 
 
 
 
53
 
54
- options = gr.CheckboxGroup(
55
- ["float32", "float16", "int8", "int4"],
56
- )
 
 
57
 
58
- library = gr.Radio(["auto", "transformers", "timm"], label="Library", value="auto")
 
 
 
 
 
 
 
 
59
 
60
- iface = gr.Interface(
61
- fn=calculate_memory,
62
- inputs=[
63
- "text",
64
- library,
65
- options,
66
- ],
67
- outputs="dataframe"
68
- )
69
 
70
- iface.launch()
 
 
 
 
 
45
  "Total Size": dtype_total_size,
46
  "Training using Adam": dtype_training_size
47
  })
48
+ return f'## {title}', pd.DataFrame(data)
 
 
 
49
 
50
+ with gr.Blocks() as demo:
51
+ gr.Markdown(
52
+ """# Model Memory Calculator
53
 
54
+ This tool will help you calculate how much vRAM is needed to train and perform big model inference
55
+ on a model hosted on the :hugging_face: Hugging Face Hub. The minimum recommended vRAM needed for a model
56
+ is denoted as the size of the "largest layer", and training of a model is roughly 4x its size (for Adam).
57
+
58
+ Currently this tool supports all models hosted that use `transformers` and `timm`.
59
 
60
+ To use this tool pass in the URL or model name of the model you want to calculate the memory usage for,
61
+ select which framework it originates from ("auto" will try and detect it from the model metadata), and
62
+ what precisions you want to use.
63
+ """
64
+ )
65
+ out_text = gr.Markdown()
66
+ out = gr.DataFrame(
67
+ headers=["dtype", "Largest Layer", "Total Size", "Training using Adam"],
68
+ )
69
 
70
+ inp = gr.Textbox(label="Model Name or URL")
71
+ with gr.Row():
72
+ library = gr.Radio(["auto", "transformers", "timm"], label="Library", value="auto")
73
+ options = gr.CheckboxGroup(
74
+ ["float32", "float16", "int8", "int4"],
75
+ value="float32"
76
+ )
77
+ btn = gr.Button("Calculate Memory Usage", scale=0.5)
 
78
 
79
+ btn.click(
80
+ calculate_memory, inputs=[inp, library, options], outputs=[out_text, out],
81
+ )
82
+
83
+ demo.launch()