-
-
Notifications
You must be signed in to change notification settings - Fork 11.7k
Fix IntermediateTensors initialization and add type hints #28743
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix IntermediateTensors initialization and add type hints #28743
Conversation
Signed-off-by: Mohammad Othman <Mo@MohammadOthman.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request adds type hints to the __init__ method of the IntermediateTensors dataclass, which is a good improvement for type safety and code clarity. However, I noticed that the custom __init__ method doesn't initialize the kv_connector_output field defined in the class. This could lead to AttributeError exceptions at runtime. I've provided a suggestion to update the __init__ method to ensure all class fields are properly initialized, making the class more robust.
vllm/sequence.py
Outdated
| kv_connector_output: KVConnectorOutput | None | ||
|
|
||
| def __init__(self, tensors): | ||
| def __init__(self, tensors: dict[str, torch.Tensor]) -> None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The custom __init__ method does not initialize the kv_connector_output field. Since IntermediateTensors is a dataclass with a custom __init__, it is responsible for initializing all fields that do not have a default value. Currently, kv_connector_output is not initialized upon object creation, which will cause an AttributeError if it's accessed before being explicitly set elsewhere.
To fix this, you should initialize it within __init__, likely with a default value of None. This requires updating both the method signature and its body.
I've suggested a change for the signature below. You will also need to add self.kv_connector_output = kv_connector_output inside the method body to complete the fix.
| def __init__(self, tensors: dict[str, torch.Tensor]) -> None: | |
| def __init__(self, tensors: dict[str, torch.Tensor], kv_connector_output: KVConnectorOutput | None = None) -> None: |
Signed-off-by: Mohammad Othman <Mo@MohammadOthman.com>
|
@gemini-code-assist I've updated the |
|
Thanks for the update, @OthmanMohammad! I've reviewed the changes to the |
Signed-off-by: Mohammad Othman <Mo@MohammadOthman.com>
…ct#28743) Signed-off-by: Mohammad Othman <Mo@MohammadOthman.com> Co-authored-by: Mohammad Othman <Mo@MohammadOthman.com> Signed-off-by: George D. Torres <gdavtor@gmail.com>
…ct#28743) Signed-off-by: Mohammad Othman <Mo@MohammadOthman.com> Co-authored-by: Mohammad Othman <Mo@MohammadOthman.com> Signed-off-by: Bram Wasti <bwasti@meta.com>
…ct#28743) Signed-off-by: Mohammad Othman <Mo@MohammadOthman.com> Co-authored-by: Mohammad Othman <Mo@MohammadOthman.com>
…ct#28743) Signed-off-by: Mohammad Othman <Mo@MohammadOthman.com> Co-authored-by: Mohammad Othman <Mo@MohammadOthman.com>
…ct#28743) Signed-off-by: Mohammad Othman <Mo@MohammadOthman.com> Co-authored-by: Mohammad Othman <Mo@MohammadOthman.com>
Purpose
Add missing type hints and fix field initialization bug in
IntermediateTensors.__init__method invllm/sequence.py.Changes:
tensorsparameter:dict[str, torch.Tensor]kv_connector_outputparameter with default valueNonekv_connector_outputfield was not initialized in custom__init__, which could causeAttributeErrorat runtimeChanges
vllm/sequence.py:63-68tensorsandkv_connector_outputparameters-> Nonekv_connector_outputfield in method bodyBenefits
kv_connector_outputcould be accessed before initializationTest Plan
Test Result
✅ File compiles successfully with correct type annotations. ✅ Class instantiates properly with all fields initialized. ✅ kv_connector_output defaults to None when not provided.
Essential Elements of an Effective PR Description Checklist
supported_models.mdandexamplesfor a new model.