Skip to content

Commit 288eb68

Browse files
committed
fix OOM bug: direct exception
1 parent cc13200 commit 288eb68

8 files changed

Lines changed: 9 additions & 27 deletions

File tree

FlagEmbedding/inference/embedder/decoder_only/base.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,7 @@ def encode_single_device(
180180
last_hidden_state = self.model(**test_inputs_batch, return_dict=True).last_hidden_state
181181
embeddings = last_token_pool(last_hidden_state, test_inputs_batch['attention_mask'])
182182
flag = True
183-
except RuntimeError as e:
184-
batch_size = batch_size * 3 // 4
185-
except torch.OutOfMemoryError as e:
183+
except:
186184
batch_size = batch_size * 3 // 4
187185

188186
# encode

FlagEmbedding/inference/embedder/decoder_only/icl.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -278,9 +278,7 @@ def encode_queries_single_device(
278278
last_hidden_state = self.model(**test_inputs_batch, return_dict=True).last_hidden_state
279279
embeddings = last_token_pool(last_hidden_state, test_inputs_batch['attention_mask'])
280280
flag = True
281-
except RuntimeError as e:
282-
batch_size = batch_size * 3 // 4
283-
except torch.OutOfMemoryError as e:
281+
except:
284282
batch_size = batch_size * 3 // 4
285283

286284
# encode
@@ -391,9 +389,7 @@ def encode_single_device(
391389
last_hidden_state = self.model(**test_inputs_batch, return_dict=True).last_hidden_state
392390
embeddings = last_token_pool(last_hidden_state, test_inputs_batch['attention_mask'])
393391
flag = True
394-
except RuntimeError as e:
395-
batch_size = batch_size * 3 // 4
396-
except torch.OutOfMemoryError as e:
392+
except:
397393
batch_size = batch_size * 3 // 4
398394

399395
# encode

FlagEmbedding/inference/embedder/encoder_only/base.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,7 @@ def encode_single_device(
170170
last_hidden_state = self.model(**test_inputs_batch, return_dict=True).last_hidden_state
171171
embeddings = self.pooling(last_hidden_state, test_inputs_batch['attention_mask'])
172172
flag = True
173-
except RuntimeError as e:
174-
batch_size = batch_size * 3 // 4
175-
except torch.OutOfMemoryError as e:
173+
except:
176174
batch_size = batch_size * 3 // 4
177175

178176
# encode

FlagEmbedding/inference/embedder/encoder_only/m3.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -304,9 +304,7 @@ def _process_colbert_vecs(colbert_vecs: np.ndarray, attention_mask: list):
304304
return_colbert_vecs=return_colbert_vecs
305305
)
306306
flag = True
307-
except RuntimeError as e:
308-
batch_size = batch_size * 3 // 4
309-
except torch.OutOfMemoryError as e:
307+
except:
310308
batch_size = batch_size * 3 // 4
311309

312310
# encode

FlagEmbedding/inference/reranker/decoder_only/base.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -317,9 +317,7 @@ def compute_score_single_gpu(
317317

318318
self.model(**batch_inputs, output_hidden_states=True)
319319
flag = True
320-
except RuntimeError as e:
321-
batch_size = batch_size * 3 // 4
322-
except torch.OutOfMemoryError as e:
320+
except:
323321
batch_size = batch_size * 3 // 4
324322

325323
dataset, dataloader = None, None

FlagEmbedding/inference/reranker/decoder_only/layerwise.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -225,9 +225,7 @@ def compute_score_single_gpu(
225225

226226
self.model(**batch_inputs, output_hidden_states=True, cutoff_layers=cutoff_layers)
227227
flag = True
228-
except RuntimeError as e:
229-
batch_size = batch_size * 3 // 4
230-
except torch.OutOfMemoryError as e:
228+
except:
231229
batch_size = batch_size * 3 // 4
232230

233231
dataset, dataloader = None, None

FlagEmbedding/inference/reranker/decoder_only/lightweight.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -300,9 +300,7 @@ def compute_score_single_gpu(
300300
cutoff_layers=cutoff_layers
301301
)
302302
flag = True
303-
except RuntimeError as e:
304-
batch_size = batch_size * 3 // 4
305-
except torch.OutOfMemoryError as e:
303+
except:
306304
batch_size = batch_size * 3 // 4
307305

308306
all_scores = []

FlagEmbedding/inference/reranker/encoder_only/base.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,7 @@ def compute_score_single_gpu(
134134
).to(device)
135135
scores = self.model(**test_inputs_batch, return_dict=True).logits.view(-1, ).float()
136136
flag = True
137-
except RuntimeError as e:
138-
batch_size = batch_size * 3 // 4
139-
except torch.OutOfMemoryError as e:
137+
except:
140138
batch_size = batch_size * 3 // 4
141139

142140
all_scores = []

0 commit comments

Comments
 (0)