Skip to content

Commit ed04b57

Browse files
committed
Update
[ghstack-poisoned]
1 parent 4fece22 commit ed04b57

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

xtuner/v1/model/moe/moe.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,14 @@ def _forward(
618618
if input_ids is not None:
619619
hidden_states = self.embed_tokens(input_ids)
620620
else:
621-
hidden_states = seq_ctx.inputs_embeds
621+
assert seq_ctx.inputs_embeds is not None, "inputs_embeds should not be None when input_ids is None"
622+
# The clone here is mainly for ActivationOffload. The current offload implementation modifies
623+
# the input tensor in-place, causing subsequent accesses to input_embeds to get a tensor with
624+
# empty storage and trigger errors. So we clone here to ensure later accesses to input_embeds
625+
# won't fail. However, there are two remaining caveats:
626+
# 1. The extra clone may introduce a slight performance overhead.
627+
# 2. hidden_states itself still cannot be reused, as offload will leave it with empty storage.
628+
hidden_states = seq_ctx.inputs_embeds.clone()
622629

623630
# create position embeddings to be shared across the decoder layers
624631
assert position_ids is not None

0 commit comments

Comments
 (0)