-
Notifications
You must be signed in to change notification settings - Fork 205
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
Support FP8 model fallback KVCache to bfloat16 #1505
base: main
Are you sure you want to change the base?
Conversation
@@ -628,10 +628,14 @@ def pre_attn_forward( | |||
else: | |||
if past_key_value is None: | |||
past_key = torch.zeros( | |||
key_states.shape, dtype=self.get_k_proj_weight_dtype(), device=key_states.device | |||
key_states.shape, | |||
dtype=torch.bfloat16 if isinstance(self.k_cache, KVCache) else self.get_k_proj_weight_dtype(), |
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.
Why not use the function?
The default value is:
self.k_proj.weight.dtype
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.
for recipes FP8Config(allowlist={"types": ["Linear"], "names": []}, blocklist=blocklist = {"types": [], "names": []})
, self.k_proj.weight.dtype
is torch.float8_e4m3fn, but the past_key
dtype should be torch.bfloat16
) | ||
past_value = torch.zeros( | ||
key_states.shape, dtype=self.get_k_proj_weight_dtype(), device=key_states.device | ||
key_states.shape, | ||
dtype=torch.bfloat16 if isinstance(self.v_cache, KVCache) else self.get_k_proj_weight_dtype(), |
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.
same
I plan to load fp8 model with the following config, Linear is fp8 and kvcache and others op are bf16.
when use
run_generation.py
do model.generate, the error raised.