Skip to content

Conversation

@Liziqi-77
Copy link
Contributor

@Liziqi-77 Liziqi-77 commented Oct 24, 2025

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?

@github-actions
Copy link

👋 Hi! Thank you for contributing to the vLLM Ascend project. The following points will speed up your PR merge:‌‌

  • A PR should do only one thing, smaller PRs enable faster reviews.
  • Every PR should include unit tests and end-to-end tests ‌to ensure it works and is not broken by other future PRs.
  • Write the commit message by fulfilling the PR description to help reviewer and future developers understand.

If CI fails, you can run linting and testing checks locally according Contributing and Testing.

@github-actions github-actions bot added documentation Improvements or additions to documentation module:tests labels Oct 24, 2025
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

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.

Suggested change
"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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

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.

Suggested change
global_segment_size: int | str
global_segment_size: int

Comment on lines 438 to 441
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)
),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

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.

Suggested change
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"
),

Comment on lines 458 to 502
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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

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)
Copy link
Contributor

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"?

Copy link
Contributor Author

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?

Copy link
Contributor

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():
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Modified

@Liziqi-77 Liziqi-77 force-pushed the vllm_mk branch 2 times, most recently from f0b4376 to a5ec9e0 Compare October 28, 2025 02:27
@yiz-liu yiz-liu added ready read for review ready-for-test start test by label for PR labels Nov 4, 2025
@github-actions
Copy link

github-actions bot commented Nov 5, 2025

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]>
B
Conflict resolution

Signed-off-by: 李子琦 <[email protected]>
@yiz-liu yiz-liu merged commit 25b24c0 into vllm-project:main Nov 6, 2025
24 checks passed
MrZ20 pushed a commit to MrZ20/vllm-ascend that referenced this pull request Nov 6, 2025
…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]>
luolun pushed a commit to luolun/vllm-ascend that referenced this pull request Nov 19, 2025
…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]>
hwhaokun pushed a commit to hwhaokun/vllm-ascend that referenced this pull request Nov 19, 2025
…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]>
NSDie pushed a commit to NSDie/vllm-ascend that referenced this pull request Nov 24, 2025
…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]>
Clorist33 pushed a commit to Clorist33/vllm-ascend that referenced this pull request Dec 10, 2025
…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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation module:tests ready read for review ready-for-test start test by label for PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants