Update app.py
Browse files
app.py
CHANGED
|
@@ -14,7 +14,12 @@ You can also use 🐣e5-mistral🛌🏻 by cloning this space. 🧬🔬🔍 Simp
|
|
| 14 |
Join us : 🌟TeamTonic🌟 is always making cool demos! Join our active builder's🛠️community on 👻Discord: [](https://discord.gg/GWpVpekp) On 🤗Huggingface: [TeamTonic](https://huggingface.co/TeamTonic) & [MultiTransformer](https://huggingface.co/MultiTransformer) On 🌐Github: [Polytonic](https://github.com/tonic-ai) & contribute to 🌟 [Poly](https://github.com/tonic-ai/poly)
|
| 15 |
"""
|
| 16 |
|
| 17 |
-
os.environ['PYTORCH_CUDA_ALLOC_CONF'] = 'max_split_size_mb:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
def last_token_pool(last_hidden_states: Tensor, attention_mask: Tensor) -> Tensor:
|
| 20 |
left_padding = (attention_mask[:, -1].sum() == attention_mask.shape[0])
|
|
@@ -28,16 +33,10 @@ def last_token_pool(last_hidden_states: Tensor, attention_mask: Tensor) -> Tenso
|
|
| 28 |
def get_detailed_instruct(task_description: str, query: str) -> str:
|
| 29 |
return f'Instruct: {task_description}\nQuery: {query}'
|
| 30 |
|
| 31 |
-
|
| 32 |
@spaces.GPU
|
| 33 |
def compute_embeddings(*input_texts):
|
| 34 |
-
|
| 35 |
-
torch.backends.cudnn.allow_tf32 = True
|
| 36 |
-
torch.backends.cudnn.benchmark = True
|
| 37 |
-
tokenizer = AutoTokenizer.from_pretrained('intfloat/e5-mistral-7b-instruct')
|
| 38 |
-
model = AutoModel.from_pretrained('intfloat/e5-mistral-7b-instruct')
|
| 39 |
-
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 40 |
-
model.to(device)
|
| 41 |
max_length = 4096
|
| 42 |
task = 'Given a web search query, retrieve relevant passages that answer the query'
|
| 43 |
|
|
|
|
| 14 |
Join us : 🌟TeamTonic🌟 is always making cool demos! Join our active builder's🛠️community on 👻Discord: [](https://discord.gg/GWpVpekp) On 🤗Huggingface: [TeamTonic](https://huggingface.co/TeamTonic) & [MultiTransformer](https://huggingface.co/MultiTransformer) On 🌐Github: [Polytonic](https://github.com/tonic-ai) & contribute to 🌟 [Poly](https://github.com/tonic-ai/poly)
|
| 15 |
"""
|
| 16 |
|
| 17 |
+
# os.environ['PYTORCH_CUDA_ALLOC_CONF'] = 'max_split_size_mb:50'
|
| 18 |
+
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 19 |
+
|
| 20 |
+
tokenizer = AutoTokenizer.from_pretrained('intfloat/e5-mistral-7b-instruct')
|
| 21 |
+
model = AutoModel.from_pretrained('intfloat/e5-mistral-7b-instruct')
|
| 22 |
+
model.to(device)
|
| 23 |
|
| 24 |
def last_token_pool(last_hidden_states: Tensor, attention_mask: Tensor) -> Tensor:
|
| 25 |
left_padding = (attention_mask[:, -1].sum() == attention_mask.shape[0])
|
|
|
|
| 33 |
def get_detailed_instruct(task_description: str, query: str) -> str:
|
| 34 |
return f'Instruct: {task_description}\nQuery: {query}'
|
| 35 |
|
| 36 |
+
|
| 37 |
@spaces.GPU
|
| 38 |
def compute_embeddings(*input_texts):
|
| 39 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
max_length = 4096
|
| 41 |
task = 'Given a web search query, retrieve relevant passages that answer the query'
|
| 42 |
|