Skip to content

Commit 792d6df

Browse files
committed
fix
1 parent 022c882 commit 792d6df

File tree

1 file changed

+2
-17
lines changed

1 file changed

+2
-17
lines changed

tests/models/phimoe/test_modeling_phimoe.py

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ def forward(
5959
past_key_values=self.cache,
6060
).logits
6161

62+
@torch.no_grad()
6263
@staticmethod
6364
def generate(model: PhimoeForCausalLM, prompt_tokens: torch.LongTensor, max_seq_len: int) -> list[int]:
6465
model = PhimoeMiniWithStaticCache(model, 1, max_seq_len + prompt_tokens.shape[-1])
@@ -194,19 +195,6 @@ def test_phimoe_instruct_generation(self):
194195

195196
def test_phimoe_instruct_with_static_cache(self):
196197
model = self.get_model()
197-
# Can't run with the real checkpoint, even if offloaded. Let's just use a tiny dummy one
198-
config = copy.deepcopy(model.config)
199-
config.num_hidden_layers = 2
200-
# make `head_dim = 128`
201-
config.hidden_size = 512
202-
config.num_attention_heads = 4
203-
config.num_key_value_heads = 1
204-
config.intermediate_size = 512
205-
config.max_position_embeddinqgs = 64
206-
config.num_local_experts = 4
207-
torch.manual_seed(42)
208-
model = PhimoeForCausalLM(config).to(torch_device)
209-
model.eval()
210198
tokenizer = AutoTokenizer.from_pretrained("microsoft/Phi-3.5-MoE-instruct")
211199

212200
messages = [
@@ -221,12 +209,9 @@ def test_phimoe_instruct_with_static_cache(self):
221209
)
222210

223211
response_tokens = PhimoeMiniWithStaticCache.generate(model, inputs, max_seq_len=30)
224-
225212
output_text = tokenizer.batch_decode(torch.tensor([response_tokens], dtype=torch.long, device=torch_device))
226213

227-
# This is dummy outputs. We actually check if it could run with static cache, not the output quality.
228214
EXPECTED_OUTPUT = [
229-
"<|system|> You are a helpful digital assistant. Please provide safe, ethical and accurate information to the user.<|end|><|user|> Can you provide ways to eat combinations of bananas and dragonfruits?<|end|><|assistant|> awards"
215+
"<|system|> You are a helpful digital assistant. Please provide safe, ethical and accurate information to the user.<|end|><|user|> Can you provide ways to eat combinations of bananas and dragonfruits?<|end|><|assistant|> C"
230216
]
231-
232217
self.assertListEqual(output_text, EXPECTED_OUTPUT)

0 commit comments

Comments
 (0)