Skip to content
Permalink
Browse files

less call to detached

  • Loading branch information...
pommedeterresautee committed Sep 19, 2019
1 parent 64dabf7 commit 1df3b05ac99a16736442c53ad48a38a2e2457f35
Showing with 3 additions and 4 deletions.
  1. +3 −4 flair/embeddings.py
@@ -1799,6 +1799,9 @@ def _add_embeddings_internal(self, sentences: List[Sentence]) -> List[Sentence]:
text_sentences, start_marker, end_marker, self.chars_per_chunk
)

if not self.fine_tune:
all_hidden_states_in_lm = all_hidden_states_in_lm.detach()

# take first or last hidden states from language model as word representation
for i, sentence in enumerate(sentences):
sentence_text = sentence.to_tokenized_string()
@@ -1823,16 +1826,12 @@ def _add_embeddings_internal(self, sentences: List[Sentence]) -> List[Sentence]:

offset_backward -= len(token.text)

if not self.fine_tune:
embedding = embedding.detach()

# only clone if optimization mode is 'gpu'
if flair.embedding_storage_mode == "gpu":
embedding = embedding.clone()

token.set_embedding(self.name, embedding)

all_hidden_states_in_lm = all_hidden_states_in_lm.detach()
del all_hidden_states_in_lm

return sentences

0 comments on commit 1df3b05

Please sign in to comment.
You can’t perform that action at this time.