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

Engine side fix for loading llama checkpoint fine-tuned with zero3 #3981

Merged
merged 5 commits into from
Jul 26, 2023

Conversation

minjiaz
Copy link
Contributor

@minjiaz minjiaz commented Jul 18, 2023

The loading of the Llama checkpoint is broken if we fine-tune it with zero-3. This issue prevents the loading of the Llama fine-tuned actor and critic models in DS-Chat for PPO stage 3 fine-tuning. The problem has been resolved by making the Llama container policy aware of zero-3.

@XuehaiPan
Copy link
Contributor

Hi, the DeepSpeed Team, I encountered the same issue while enabling HybridEngine for the LLaMA model with ZeRO-3.

After several hours of debugging, I found a similar fix:

    def get_hidden_heads(self):
-       return self.client_module.self_attn.q_proj.weight.shape[1], \
+       return self.client_module.self_attn.q_proj.in_features, \
                self.client_module.self_attn.num_heads, \
                self.client_module.input_layernorm.variance_epsilon, \
-               self.client_module.mlp.gate_proj.weight.shape[0]
+               self.client_module.mlp.gate_proj.out_features

Comment on lines 125 to 134
try: # for zero stage 3
return self.client_module.self_attn.q_proj.weight.ds_shape[1], \
self.client_module.self_attn.num_heads, \
self.client_module.input_layernorm.variance_epsilon, \
self.client_module.mlp.gate_proj.weight.ds_shape[0]
except:
return self.client_module.self_attn.q_proj.weight.shape[1], \
self.client_module.self_attn.num_heads, \
self.client_module.input_layernorm.variance_epsilon, \
self.client_module.mlp.gate_proj.weight.shape[0]
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be nicer with temp variable + getattr.

Suggested change
try: # for zero stage 3
return self.client_module.self_attn.q_proj.weight.ds_shape[1], \
self.client_module.self_attn.num_heads, \
self.client_module.input_layernorm.variance_epsilon, \
self.client_module.mlp.gate_proj.weight.ds_shape[0]
except:
return self.client_module.self_attn.q_proj.weight.shape[1], \
self.client_module.self_attn.num_heads, \
self.client_module.input_layernorm.variance_epsilon, \
self.client_module.mlp.gate_proj.weight.shape[0]
q_proj_weight = self.client_module.self_attn.q_proj.weight
gate_proj_weight = self.client_module.mlp.gate_proj.weight
return getattr(q_proj_weight, "ds_shape", q_proj_weight.shape)[1], \
self.client_module.self_attn.num_heads, \
self.client_module.input_layernorm.variance_epsilon, \
getattr(gate_proj_weight, "ds_shape", gate_proj_weight.shape)[0]

@mrwyattii mrwyattii enabled auto-merge July 26, 2023 22:16
@mrwyattii mrwyattii added this pull request to the merge queue Jul 26, 2023
Merged via the queue into master with commit 15f94ae Jul 26, 2023
polisettyvarma pushed a commit to polisettyvarma/DeepSpeed that referenced this pull request Aug 7, 2023
…icrosoft#3981)

* Engine side fix for loading llama checkpoint fine-tuned with zero3

* Fixes to support llama fine-tuning in ds-chat

* Refactored the code to avoid using an except block.

* formatting

* revert permissions change

---------

Co-authored-by: Michael Wyatt <michaelwyatt@microsoft.com>
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