-
Notifications
You must be signed in to change notification settings - Fork 744
[Loader] Add values natural order check to layers grouped validation #7498
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -40,7 +40,7 @@ | |
| from tqdm import tqdm | ||
|
|
||
| from fastdeploy import envs | ||
| from fastdeploy.config import FDConfig, LoadConfig | ||
| from fastdeploy.config import FDConfig | ||
| from fastdeploy.model_executor.layers.linear import KVBatchLinear | ||
| from fastdeploy.model_executor.utils import multi_switch_config_context | ||
|
|
||
|
|
@@ -72,6 +72,11 @@ def layers_are_grouped(keys): | |
| return True | ||
|
|
||
|
|
||
| def values_are_naturally_ordered(values): | ||
| """Check if values are sorted in natural order.""" | ||
| return list(values) == sorted(values, key=natural_key) | ||
This comment was marked as outdated.
Sorry, something went wrong. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 建议 该函数是此 PR 核心修复逻辑的入口,但测试文件中未新增对应测试用例。现有 建议补充:
此逻辑是 OOM 修复的关键路径,回归测试缺失时风险较高。 |
||
|
|
||
|
|
||
| def pdparams_weight_iterator(paddle_file_list: list[str]): | ||
| for pdparams_file in tqdm( | ||
| paddle_file_list, | ||
|
|
@@ -117,18 +122,20 @@ def get_model_path(fd_config: FDConfig): | |
| return model_path | ||
|
|
||
|
|
||
| def get_weight_iterator(model_path: str, load_config: Optional[LoadConfig] = None): | ||
| def get_weight_iterator(model_path: str, fd_config: Optional[FDConfig] = None): | ||
| files_list, ordered_weight_map, use_safetensors, is_layers_are_grouped = get_all_weights_file(model_path) | ||
| if use_safetensors: | ||
| load_config = fd_config.load_config if fd_config else None | ||
| extra_config = load_config.model_loader_extra_config if load_config else None | ||
| parallel_config = fd_config.parallel_config if fd_config else None | ||
| if extra_config is not None and extra_config.get("enable_multithread_load", False): | ||
| weights_iterator = multi_thread_safetensors_weights_iterator( | ||
| files_list, | ||
| max_workers=extra_config.get("num_threads", DEFAULT_NUM_THREADS), | ||
| disable_mmap=extra_config.get("disable_mmap", False), | ||
| ) | ||
| else: | ||
| if is_layers_are_grouped: | ||
| if is_layers_are_grouped or (parallel_config is not None and parallel_config.tensor_parallel_size == 1): | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 建议 新增的 TP=1 短路条件缺少注释说明意图 当 建议加上注释说明: if is_layers_are_grouped or (
# For TP=1, sequential file-by-file loading is always safe and avoids
# the OOM risk of safetensors_weights_iterator_ordered jumping between
# shard files in non-sequential order.
parallel_config is not None and parallel_config.tensor_parallel_size == 1
): |
||
| weights_iterator = safetensors_weights_iterator(files_list) | ||
| else: | ||
| weights_iterator = safetensors_weights_iterator_ordered(ordered_weight_map) | ||
|
|
@@ -532,7 +539,10 @@ def get_all_weights_file(model_path: str): | |
| with index_file.open("r") as f: | ||
| weight_map = json.load(f)["weight_map"] | ||
| keys = list(weight_map.keys()) | ||
| is_layers_are_grouped = layers_are_grouped(keys) | ||
| values = list(weight_map.values()) | ||
| is_keys_orders = layers_are_grouped(keys) | ||
This comment was marked as outdated.
Sorry, something went wrong.
This comment was marked as outdated.
Sorry, something went wrong. |
||
| is_values_naturally_ordered = values_are_naturally_ordered(values) | ||
| is_layers_are_grouped = is_keys_orders and is_values_naturally_ordered | ||
| ordered_weight_map = { | ||
| key: str(model_path / weight_map[key]) for key in sorted(weight_map.keys(), key=natural_key) | ||
| } | ||
|
|
||
This comment was marked as outdated.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.