Skip to content

Commit

Permalink
Update lm.py to suit OPT-like models
Browse files Browse the repository at this point in the history
Some newer models like OPT treat embedding layers as a separate layer 'Embedding' instead of pure tensor.
  • Loading branch information
BiEchi authored Jul 22, 2023
1 parent 0ef61c5 commit aab5b7d
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/ecco/lm.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,10 @@ def __init__(self,
self.model_type = self.model_config['type']
embeddings_layer_name = self.model_config['embedding']
embed_retriever = attrgetter(embeddings_layer_name)
self.model_embeddings = embed_retriever(self.model)
if type(embed_retriever(self.model)) == torch.nn.Embedding:
self.model_embeddings = embed_retriever(self.model).weight
else:
self.model_embeddings = embed_retriever(self.model)
self.collect_activations_layer_name_sig = self.model_config['activations'][0]
except KeyError:
raise ValueError(
Expand Down

0 comments on commit aab5b7d

Please sign in to comment.