Skip to content

cannot unpack non-iterable NoneType object #13

@CYWYKKK

Description

@CYWYKKK

I have a exception problem "cannot unpack non-iterable NoneType object",this problem may be involved in the following code,plz help me:
def generate_embeddings(self, text: str) -> FullEmbeddings:
all_layer_embeddings: Dict[int, LayerEmbeddings] = {}

    def split_embedding(embedding: List[float], chunk_size: int) -> List[List[float]]
        return [embedding[i:i+chunk_size] for i in range(0, len(embedding), chunk_size)]

    with torch.no_grad():  

        batch_dict = self._tokenizer([text], padding=True, return_tensors="pt")
        input_ids = batch_dict["input_ids"].to(self._model.device)
        hidden_states = self._model.embed_tokens(input_ids)  


        for layer_idx, layer in enumerate(self._model.layers):

            hidden_states = layer(hidden_states)[0]


            if layer_idx in self.target_layers:
                o_proj_input = layer.self_attn.o_proj.last_input
                if o_proj_input is not None:

                    last_token_o_input = o_proj_input[0][-1]

                    layer_emb = LayerEmbeddings(split_embedding(last_token_o_input.tolist(), 128))
                    all_layer_embeddings[layer_idx] = layer_emb


        standard_emb = self._model.norm(hidden_states)[0][-1].tolist()

    return FullEmbeddings(standard_embedding=standard_emb, layer_embeddings=all_layer_embeddings)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions