asoria HF staff commited on
Commit
2441f3f
1 Parent(s): c77685f

Remove zero GPU code temporaly

Browse files
Files changed (2) hide show
  1. app.py +12 -17
  2. requirements.txt +2 -2
app.py CHANGED
@@ -1,10 +1,9 @@
1
- import spaces
2
  import requests
3
  import logging
4
  import duckdb
5
  from gradio_huggingfacehub_search import HuggingfaceHubSearch
6
  from bertopic import BERTopic
7
- import pandas as pd
8
  import gradio as gr
9
  from bertopic.representation import (
10
  KeyBERTInspired,
@@ -13,10 +12,9 @@ from bertopic.representation import (
13
  )
14
  from umap import UMAP
15
  import numpy as np
16
- from torch import cuda
17
- from torch import bfloat16
18
  from transformers import (
19
- # BitsAndBytesConfig,
20
  AutoTokenizer,
21
  AutoModelForCausalLM,
22
  pipeline,
@@ -44,12 +42,12 @@ model_id = "meta-llama/Llama-2-7b-chat-hf"
44
  device = f"cuda:{cuda.current_device()}" if cuda.is_available() else "cpu"
45
  logging.info(device)
46
 
47
- # bnb_config = BitsAndBytesConfig(
48
- # load_in_4bit=True, # 4-bit quantization
49
- # bnb_4bit_quant_type="nf4", # Normalized float 4
50
- # bnb_4bit_use_double_quant=True, # Second quantization after the first
51
- # bnb_4bit_compute_dtype=bfloat16, # Computation type
52
- # )
53
 
54
  tokenizer = AutoTokenizer.from_pretrained(model_id)
55
 
@@ -57,7 +55,7 @@ tokenizer = AutoTokenizer.from_pretrained(model_id)
57
  model = AutoModelForCausalLM.from_pretrained(
58
  model_id,
59
  trust_remote_code=True,
60
- # quantization_config=bnb_config,
61
  device_map="auto",
62
  )
63
 
@@ -113,12 +111,12 @@ def get_docs_from_parquet(parquet_urls, column, offset, limit):
113
  return df[column].tolist()
114
 
115
 
116
- @spaces.GPU
117
  def calculate_embeddings(docs):
118
  return sentence_model.encode(docs, show_progress_bar=True, batch_size=100)
119
 
120
 
121
- @spaces.GPU
122
  def fit_model(base_model, docs, embeddings):
123
  new_model = BERTopic(
124
  "english",
@@ -242,9 +240,6 @@ with gr.Blocks() as demo:
242
  outputs=[topics_df, topics_plot],
243
  )
244
 
245
- # TODO: choose num_rows, random, or offset -> By default limit max to 1176 rows
246
- # -> From the article, it could be in GPU 1176/sec
247
-
248
  def _resolve_dataset_selection(
249
  dataset: str, default_subset: str, default_split: str, text_feature
250
  ):
 
1
+ # import spaces
2
  import requests
3
  import logging
4
  import duckdb
5
  from gradio_huggingfacehub_search import HuggingfaceHubSearch
6
  from bertopic import BERTopic
 
7
  import gradio as gr
8
  from bertopic.representation import (
9
  KeyBERTInspired,
 
12
  )
13
  from umap import UMAP
14
  import numpy as np
15
+ from torch import cuda, bfloat16
 
16
  from transformers import (
17
+ BitsAndBytesConfig,
18
  AutoTokenizer,
19
  AutoModelForCausalLM,
20
  pipeline,
 
42
  device = f"cuda:{cuda.current_device()}" if cuda.is_available() else "cpu"
43
  logging.info(device)
44
 
45
+ bnb_config = BitsAndBytesConfig(
46
+ load_in_4bit=True, # 4-bit quantization
47
+ bnb_4bit_quant_type="nf4", # Normalized float 4
48
+ bnb_4bit_use_double_quant=True, # Second quantization after the first
49
+ bnb_4bit_compute_dtype=bfloat16, # Computation type
50
+ )
51
 
52
  tokenizer = AutoTokenizer.from_pretrained(model_id)
53
 
 
55
  model = AutoModelForCausalLM.from_pretrained(
56
  model_id,
57
  trust_remote_code=True,
58
+ quantization_config=bnb_config,
59
  device_map="auto",
60
  )
61
 
 
111
  return df[column].tolist()
112
 
113
 
114
+ # @spaces.GPU
115
  def calculate_embeddings(docs):
116
  return sentence_model.encode(docs, show_progress_bar=True, batch_size=100)
117
 
118
 
119
+ # @spaces.GPU
120
  def fit_model(base_model, docs, embeddings):
121
  new_model = BERTopic(
122
  "english",
 
240
  outputs=[topics_df, topics_plot],
241
  )
242
 
 
 
 
243
  def _resolve_dataset_selection(
244
  dataset: str, default_subset: str, default_split: str, text_feature
245
  ):
requirements.txt CHANGED
@@ -4,8 +4,8 @@ gradio_huggingfacehub_search==0.0.7
4
  duckdb
5
  umap-learn
6
  sentence-transformers
7
- bitsandbytes-cuda110
8
- # datamapplot
9
  bertopic
10
  pandas
11
  torch
 
4
  duckdb
5
  umap-learn
6
  sentence-transformers
7
+ bitsandbytes
8
+ datamapplot
9
  bertopic
10
  pandas
11
  torch