-
Notifications
You must be signed in to change notification settings - Fork 653
[Feat](Mooncake) Supports multiple input suffixes for global_segment_size #3690
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
Conversation
|
👋 Hi! Thank you for contributing to the vLLM Ascend project. The following points will speed up your PR merge:
If CI fails, you can run linting and testing checks locally according Contributing and Testing. |
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 introduces a useful feature to support multiple input suffixes (GB, MB, KB, B) for size configurations like global_segment_size and local_buffer_size. The implementation is mostly solid and includes good test coverage. I've identified a few issues that should be addressed to improve correctness and maintainability. Specifically, the documentation contains an invalid JSON example, a type hint is incorrect, and a parsing function should be generalized to improve its reusability and error reporting. My detailed comments provide suggestions to resolve these points.
| "device_name": "", | ||
| "master_server_address": "xx.xx.xx.xx:50088", | ||
| "global_segment_size": 30000000000 | ||
| "global_segment_size": "1GB/1024MB/1048576KB/1073741824B" or 1073741824 |
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 example value for global_segment_size is not valid JSON. It appears to be demonstrating multiple possible formats in one line, which will cause a parsing error for users who copy this configuration. Please provide a single, valid example. The other formats can be explained in the documentation text below the code block.
| "global_segment_size": "1GB/1024MB/1048576KB/1073741824B" or 1073741824 | |
| "global_segment_size": "1GB" |
| local_hostname: str | ||
| metadata_server: str | ||
| global_segment_size: int | ||
| global_segment_size: int | str |
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 type hint for global_segment_size is updated to int | str. However, since the value is immediately parsed by _parse_global_segment_size which returns an int, the attribute on the MooncakeStoreConfig instance will always be an int. To accurately reflect the attribute's type after initialization, this hint should remain int. This will also maintain consistency with local_buffer_size, which is also parsed but its type hint correctly remains int.
| global_segment_size: int | str | |
| global_segment_size: int |
| global_segment_size=_parse_global_segment_size( | ||
| config.get("global_segment_size", DEFAULT_GLOBAL_SEGMENT_SIZE) | ||
| ), | ||
| local_buffer_size=_parse_global_segment_size( | ||
| config.get("local_buffer_size", DEFAULT_LOCAL_BUFFER_SIZE) | ||
| ), |
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.
To improve error message clarity, the parsing function should be made aware of the parameter it's parsing. This will allow it to produce more specific error messages (e.g., for local_buffer_size instead of a generic one). This change is part of a refactoring to make _parse_global_segment_size more generic. I've suggested renaming it to _parse_size and passing the parameter name as an argument in a separate comment.
| global_segment_size=_parse_global_segment_size( | |
| config.get("global_segment_size", DEFAULT_GLOBAL_SEGMENT_SIZE) | |
| ), | |
| local_buffer_size=_parse_global_segment_size( | |
| config.get("local_buffer_size", DEFAULT_LOCAL_BUFFER_SIZE) | |
| ), | |
| global_segment_size=_parse_size( | |
| config.get("global_segment_size", DEFAULT_GLOBAL_SEGMENT_SIZE), | |
| "global_segment_size" | |
| ), | |
| local_buffer_size=_parse_size( | |
| config.get("local_buffer_size", DEFAULT_LOCAL_BUFFER_SIZE), | |
| "local_buffer_size" | |
| ), |
| def _parse_global_segment_size(value) -> int: | ||
| """ | ||
| Parse storage size strings with support for units: GB, MB, KB, B | ||
| Args: | ||
| value: Input value (int, str, or other convertible types) | ||
| Returns: | ||
| int: Size in bytes | ||
| Raises: | ||
| ValueError: For invalid format, missing number, or negative values | ||
| TypeError: For unsupported input types | ||
| """ | ||
|
|
||
| if isinstance(value, int): | ||
| return value | ||
| elif not isinstance(value, str): | ||
| try: | ||
| return int(value) | ||
| except (TypeError, ValueError) as e: | ||
| raise TypeError(f"Unsupported type for global_segment_size: {type(value)}") from e | ||
| # Clean input string | ||
| cleaned_input = value.strip().lower() | ||
| if not cleaned_input: | ||
| raise ValueError("global segment size cannot be empty.") | ||
|
|
||
| UNIT_MULTIPLIERS = { | ||
| 'gb': 1024 ** 3, # 1 GB = 1024^3 bytes | ||
| 'mb': 1024 ** 2, # 1 MB = 1024^2 bytes | ||
| 'kb': 1024, # 1 KB = 1024 bytes | ||
| 'b': 1 # 1 B = 1 byte | ||
| } | ||
| # Check for unit suffixes | ||
| for unit, multiplier in UNIT_MULTIPLIERS.items(): | ||
| if cleaned_input.endswith(unit): | ||
| number_part = cleaned_input[:-len(unit)].strip() | ||
| if not number_part: | ||
| raise ValueError(f"Missing numeric value before unit '{unit}' in: '{value}'") | ||
| return _convert_to_bytes(number_part, multiplier, value) | ||
| # Handle unit-less input (bytes) | ||
| return _convert_to_bytes(cleaned_input, 1, value) |
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 function _parse_global_segment_size is now used for both global_segment_size and local_buffer_size, but its name and error messages are specific to global_segment_size. This is misleading and can produce confusing error messages (e.g., an error about global_segment_size when local_buffer_size is invalid). I suggest refactoring this function to be more generic by renaming it to _parse_size and passing the parameter name as an argument to be used in error messages.
def _parse_size(value, name: str) -> int:
"""
Parse storage size strings with support for units: GB, MB, KB, B
Args:
value: Input value (int, str, or other convertible types)
name: Name of the parameter being parsed (for error messages)
Returns:
int: Size in bytes
Raises:
ValueError: For invalid format, missing number, or negative values
TypeError: For unsupported input types
"""
if isinstance(value, int):
return value
elif not isinstance(value, str):
try:
return int(value)
except (TypeError, ValueError) as e:
raise TypeError(f"Unsupported type for {name}: {type(value)}") from e
# Clean input string
cleaned_input = value.strip().lower()
if not cleaned_input:
raise ValueError(f"{name} cannot be empty.")
UNIT_MULTIPLIERS = {
'gb': 1024 ** 3, # 1 GB = 1024^3 bytes
'mb': 1024 ** 2, # 1 MB = 1024^2 bytes
'kb': 1024, # 1 KB = 1024 bytes
'b': 1 # 1 B = 1 byte
}
# Check for unit suffixes
for unit, multiplier in UNIT_MULTIPLIERS.items():
if cleaned_input.endswith(unit):
number_part = cleaned_input[:-len(unit)].strip()
if not number_part:
raise ValueError(f"Missing numeric value before unit '{unit}' in: '{value}'")
return _convert_to_bytes(number_part, multiplier, value)
# Handle unit-less input (bytes)
return _convert_to_bytes(cleaned_input, 1, value)| @@ -24,7 +24,7 @@ The environment variable **MOONCAKE_CONFIG_PATH** is configured to the full path | |||
| "protocol": "ascend", | |||
| "device_name": "", | |||
| "master_server_address": "xx.xx.xx.xx:50088", | |||
| "global_segment_size": 30000000000 | |||
| "global_segment_size": "1GB" (1024MB/1048576KB/1073741824B/1073741824) | |||
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.
Should users be allowed to input "1G" instead of "1GB"?
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.
G is the colloquial form or abbreviation of GB. Would it be more appropriate to use the standard form here?
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.
It's okay to have examples
| 'b': 1 # 1 B = 1 byte | ||
| } | ||
| # Check for unit suffixes | ||
| for unit, multiplier in UNIT_MULTIPLIERS.items(): |
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.
Can a regular expression be used instead of looping through the units?
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.
Modified
f0b4376 to
a5ec9e0
Compare
|
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
Signed-off-by: 李子琦 <[email protected]>
Signed-off-by: 李子琦 <[email protected]>
Signed-off-by: 李子琦 <[email protected]>
Signed-off-by: 李子琦 <[email protected]>
Signed-off-by: 李子琦 <[email protected]>
Signed-off-by: 李子琦 <[email protected]>
Signed-off-by: 李子琦 <[email protected]>
Conflict resolution Signed-off-by: 李子琦 <[email protected]>
…size (vllm-project#3690) ### What this PR does / why we need it? - global_segment_size and local_buffer_size use constants for unified management. - Newly added support for input formats ending with GB, MB, KB, and B, while being compatible with existing input methods. ### Does this PR introduce _any_ user-facing change? - Users can use new input methods - The documentation has also been modified ### How was this patch tested? - vLLM version: v0.11.0 - vLLM main: vllm-project/vllm@83f478b --------- Signed-off-by: 李子琦 <[email protected]>
…size (vllm-project#3690) ### What this PR does / why we need it? - global_segment_size and local_buffer_size use constants for unified management. - Newly added support for input formats ending with GB, MB, KB, and B, while being compatible with existing input methods. ### Does this PR introduce _any_ user-facing change? - Users can use new input methods - The documentation has also been modified ### How was this patch tested? - vLLM version: v0.11.0 - vLLM main: vllm-project/vllm@83f478b --------- Signed-off-by: 李子琦 <[email protected]> Signed-off-by: luolun <[email protected]>
…size (vllm-project#3690) ### What this PR does / why we need it? - global_segment_size and local_buffer_size use constants for unified management. - Newly added support for input formats ending with GB, MB, KB, and B, while being compatible with existing input methods. ### Does this PR introduce _any_ user-facing change? - Users can use new input methods - The documentation has also been modified ### How was this patch tested? - vLLM version: v0.11.0 - vLLM main: vllm-project/vllm@83f478b --------- Signed-off-by: 李子琦 <[email protected]> Signed-off-by: hwhaokun <[email protected]>
…size (vllm-project#3690) ### What this PR does / why we need it? - global_segment_size and local_buffer_size use constants for unified management. - Newly added support for input formats ending with GB, MB, KB, and B, while being compatible with existing input methods. ### Does this PR introduce _any_ user-facing change? - Users can use new input methods - The documentation has also been modified ### How was this patch tested? - vLLM version: v0.11.0 - vLLM main: vllm-project/vllm@83f478b --------- Signed-off-by: 李子琦 <[email protected]> Signed-off-by: nsdie <[email protected]>
…size (vllm-project#3690) ### What this PR does / why we need it? - global_segment_size and local_buffer_size use constants for unified management. - Newly added support for input formats ending with GB, MB, KB, and B, while being compatible with existing input methods. ### Does this PR introduce _any_ user-facing change? - Users can use new input methods - The documentation has also been modified ### How was this patch tested? - vLLM version: v0.11.0 - vLLM main: vllm-project/vllm@83f478b --------- Signed-off-by: 李子琦 <[email protected]>
What this PR does / why we need it?
Does this PR introduce any user-facing change?
How was this patch tested?