TensorRT-LLM icon indicating copy to clipboard operation
TensorRT-LLM copied to clipboard

AttributeError: 'NoneType' object has no attribute 'name'

Open liminn opened this issue 1 year ago • 0 comments

I want to test OneShot AllReduce and TwoShot AllReduce separately, so I have modified the following code:

class LLaMAModel(Module):

    def __init__(self, config: PretrainedConfig) -> None:
        super().__init__()
        init_all_reduce_helper()

        self.mapping = config.mapping
        if self.mapping.is_first_pp_rank():
            self.vocab_embedding = Embedding(config.vocab_size,
                                             config.hidden_size,
                                             dtype=config.dtype)

        self.layers = DecoderLayerList(LLaMADecoderLayer, config)

        if self.mapping.is_last_pp_rank():
            self.ln_f = RmsNorm(normalized_shape=config.hidden_size,
                                eps=config.norm_epsilon,
                                dtype=config.dtype)
       
        self.tp_group=config.mapping.tp_group
        
    def forward(
            self,
            input_ids,
            position_ids=None,
            use_cache=False,
            attention_mask=None,
            medusa_position_offsets=None,  # For Medusa support
            medusa_packed_mask=None,  # For Medusa support
            kv_cache_params=None,
            attention_params=None,
            hidden_states=None,
            prompt_embedding_table: Optional[Tensor] = None,
            prompt_tasks: Optional[Tensor] = None,
            prompt_vocab_size: Optional[Tensor] = None,
            lora_params=None):

        ptuning_args = [
            prompt_embedding_table, prompt_tasks, prompt_vocab_size
        ] if prompt_embedding_table is not None else []

        if self.mapping.is_first_pp_rank():
            hidden_states = self.vocab_embedding(input_ids, *ptuning_args)
        else:
            hidden_states = recv(hidden_states, self.mapping.prev_pp_rank())

        ### Test OneShot_AllReduce and TwoShot_AllReduce
        x = Tensor(name='input_ids', dtype=trt.float16, shape=[64, 8192])
        torch.cuda.synchronize()
        for i in range(10):
             #hidden_states = allreduce(x, self.tp_group, strategy=1)
             hidden_states = allreduce(x, self.tp_group, strategy=2)
        torch.cuda.synchronize()

        return hidden_states

when I buid:

[05/07/2024-11:22:02] [TRT] [E] 3: [network.cpp::addInput::1973] Error Code 3: API Usage Error (Parameter check failed at: optimizer/api/network.cpp::addInput::1973, condition: inName != knownInput->getName() )
concurrent.futures.process._RemoteTraceback: 
Traceback (most recent call last):
  File "/usr/lib/python3.10/concurrent/futures/process.py", line 246, in _process_worker
    r = call_item.fn(*call_item.args, **call_item.kwargs)
  File "/usr/local/lib/python3.10/dist-packages/tensorrt_llm/commands/build.py", line 315, in build_and_save
    engine = build_model(build_config,
  File "/usr/local/lib/python3.10/dist-packages/tensorrt_llm/commands/build.py", line 308, in build_model
    return build(model, build_config)
  File "/usr/local/lib/python3.10/dist-packages/tensorrt_llm/builder.py", line 732, in build
    model(**inputs)
  File "/usr/local/lib/python3.10/dist-packages/tensorrt_llm/module.py", line 40, in __call__
    output = self.forward(*args, **kwargs)
  File "/usr/local/lib/python3.10/dist-packages/tensorrt_llm/models/modeling_utils.py", line 634, in forward
    hidden_states = self.transformer.forward(**kwargs)
  File "/usr/local/lib/python3.10/dist-packages/tensorrt_llm/models/llama/model.py", line 191, in forward
    x = Tensor(name='input_ids', dtype=trt.float16, shape=[64, 8192])
  File "/usr/local/lib/python3.10/dist-packages/tensorrt_llm/functional.py", line 226, in __init__
    self.name = name
  File "/usr/local/lib/python3.10/dist-packages/tensorrt_llm/functional.py", line 248, in name
    self.trt_tensor.name = name
AttributeError: 'NoneType' object has no attribute 'name'

The reason for the error is due to this line of code:x = Tensor(name='input_ids', dtype=trt.float16, shape=[64, 8192]) Why is this error reported? Is there any way for me to create a tensorrt tensor for any shape during the forward process?


In addition, I also tried to modify the shape of existing tensor hidden states , but none of them were successful. Is there any way to modify the shape of an existing tensor during the forawrd inference process?

liminn avatar May 07 '24 11:05 liminn