Skip to content
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

快速加载 #9934

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 41 additions & 15 deletions paddlenlp/experimental/transformers/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,22 +58,48 @@
# init the model
with ContextManagers(init_contexts):
model = cls(config)

if True:
resolved_archive_file, _, _, _ = cls._resolve_model_file_path(

Check warning on line 63 in paddlenlp/experimental/transformers/utils.py

View check run for this annotation

Codecov / codecov/patch

paddlenlp/experimental/transformers/utils.py#L62-L63

Added lines #L62 - L63 were not covered by tests
pretrained_model_name_or_path,
cache_dir=cache_dir,
subfolder=subfolder,
from_hf_hub=False,
from_aistudio=False,
config=config,
convert_from_torch=False,
use_safetensors=use_safetensors,
variant=variant,
)

resolved_archive_file, _, _, _ = cls._resolve_model_file_path(
pretrained_model_name_or_path,
cache_dir=cache_dir,
subfolder=subfolder,
from_hf_hub=False,
from_aistudio=False,
config=config,
convert_from_torch=False,
use_safetensors=use_safetensors,
variant=variant,
)

model_path = os.path.dirname(resolved_archive_file)
state_dict = load_tp_checkpoint(model_path, cls, config, return_numpy=return_numpy)
model.set_state_dict(state_dict)
model_path = os.path.dirname(resolved_archive_file)
state_dict = load_tp_checkpoint(model_path, cls, config, return_numpy=return_numpy)
model.set_state_dict(state_dict)

Check warning on line 77 in paddlenlp/experimental/transformers/utils.py

View check run for this annotation

Codecov / codecov/patch

paddlenlp/experimental/transformers/utils.py#L75-L77

Added lines #L75 - L77 were not covered by tests

paddle.distributed.barrier()
rank = paddle.distributed.get_rank()
file_name = f"/root/paddlejob/workspace/env_run/output/deepseekv3/{rank}.pdparams"
state_dict = model.state_dict()
paddle.save(state_dict, file_name)
exit(0)

Check warning on line 84 in paddlenlp/experimental/transformers/utils.py

View check run for this annotation

Codecov / codecov/patch

paddlenlp/experimental/transformers/utils.py#L79-L84

Added lines #L79 - L84 were not covered by tests
else:
model.deepseek_v2.transformer_block.init_weight()

for key, value in model.state_dict().items():
value._clear_data()

paddle.distributed.barrier()
rank = paddle.distributed.get_rank()
file_name = f"/root/paddlejob/workspace/env_run/output/deepseekv3/{rank}.pdparams"
state_dict = paddle.load(file_name, return_numpy=False)

for key, value in model.state_dict().items():
value._clear_data()
new_v = state_dict.pop(key)
if new_v.dtype == paddle.int8:
# support fp8
new_v = new_v.view("float8_e4m3fn")
new_v._share_buffer_to(value)

return model

Expand Down
Loading