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

fix export turbomind weight bug #1140

Closed
wants to merge 1 commit into from
Closed

fix export turbomind weight bug #1140

wants to merge 1 commit into from

Conversation

zhyncs
Copy link
Collaborator

@zhyncs zhyncs commented Feb 7, 2024

Motivation

fix export Turbomind weight bug

In the process of developing Medusa parameter conversion, we referred to the implementation of export_weight and found that there was a bug with the implementation of parameter conversion in bf16. This fix was proposed by the new grad named baozhiwei in my group.

Modification

use tensor.to rather than tensor.view

Checklist

  1. Pre-commit or other linting tools are used to fix the potential lint issues.
  2. The modification is covered by complete unit tests. If not, please add more unit tests to ensure the correctness.
  3. If the modification has a dependency on downstream projects of a newer version, this PR should be tested with all supported versions of downstream projects.
  4. The documentation has been modified accordingly, like docstring or example tutorials.

@zhyncs
Copy link
Collaborator Author

zhyncs commented Feb 7, 2024

Hi @lvhan028 @grimoire @AllentDan May you help review this pr? Thanks.

@RunningLeon RunningLeon added bug Something isn't working and removed bug Something isn't working labels Feb 7, 2024
@irexyc
Copy link
Collaborator

irexyc commented Feb 7, 2024

这个地方没问题,因为numpy没有bfloat16的类型,所以如果想保存bin的话,只能以view的形式保存。

@RunningLeon
Copy link
Collaborator

@zhyncs FYI, https://pytorch.org/docs/stable/generated/torch.Tensor.view.html#torch-tensor-view

@zhyncs
Copy link
Collaborator Author

zhyncs commented Feb 7, 2024

这个地方没问题,因为numpy没有bfloat16的类型,所以如果想保存bin的话,只能以view的形式保存。

tensor.view only changes the shape and cannot do type conversion from bf16 to half

@irexyc
Copy link
Collaborator

irexyc commented Feb 7, 2024

if self.to_file:
if torch.is_floating_point(param):
torch_type = _weight_dtype_map(self.cfg.weight_type,
torch.float16)
param = param.to(torch_type)
tprint(name, param.shape)
_tofile(param, osp.join(self.out_dir, name))

看下191行,这里本来就是要保存bfloat16

@zhyncs
Copy link
Collaborator Author

zhyncs commented Feb 7, 2024

if self.to_file:
if torch.is_floating_point(param):
torch_type = _weight_dtype_map(self.cfg.weight_type,
torch.float16)
param = param.to(torch_type)
tprint(name, param.shape)
_tofile(param, osp.join(self.out_dir, name))

看下191行,这里本来就是要保存bfloat16

It seems that we had some misunderstandings.

Base model lmsys/vicuna-13b-v1.3 uses half and FasterDecoding/medusa-vicuna-13b-v1.3 uses bfloat16. And when we load medusa weights, because the llama weight_type field is fp16, so

#ifdef ENABLE_BF16
template int loadWeightFromBin(__nv_bfloat16* ptr,
std::vector<size_t> shape,
std::string filename,
FtCudaDataType model_file_type,
std::vector<ConcateSlice> slices);

this is not invoked. And that's why medusa weights are wrong.
So we need to add medusa_weight_type field in ini to solve this problem or just convert and save Medusa weights with half directly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants