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

Update spec infer #15

Open
wants to merge 27 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions examples/runtime/engine/offline_batch_inference.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
import sglang as sgl

import time

def main():
# Sample prompts.
prompts = [
"Hello, my name is",
"The president of the United States is",
"The capital of France is",
"The future of AI is",
"A chat between a curious user and an artificial intelligence assistant. The assistant gives helpful, detailed, and polite answers to the user's questions. USER: Where is the capital city of France? ASSISTANT:",
"A chat between a curious user and an artificial intelligence assistant. The assistant gives helpful, detailed, and polite answers to the user's questions. USER: 北京今天天气怎么样? ASSISTANT:"
]
# Create a sampling params object.
sampling_params = {"temperature": 0.8, "top_p": 0.95}
sampling_params = {"temperature": 0, "max_new_tokens": 30}

# Create an LLM.
llm = sgl.Engine(model_path="meta-llama/Meta-Llama-3.1-8B-Instruct")

# Create an LLM.
llm = sgl.Engine(model_path="Llama-2-7b-chat-hf", draft_model_path='EAGLE-llama2-chat-7B', disable_cuda_graph=True, num_speculative_steps=5, eagle_topk=8, num_draft_tokens=64, speculative_algorithm='EAGLE', mem_fraction_static=0.60)
#llm = sgl.Engine(model_path="Llama-2-7b-chat-hf", disable_cuda_graph=False)
#outputs = llm.generate(prompts, sampling_params)
start = time.time()
outputs = llm.generate(prompts, sampling_params)
print(time.time()-start)
# Print the outputs.
for prompt, output in zip(prompts, outputs):
print("===============================")
Expand Down
13 changes: 10 additions & 3 deletions python/sglang/srt/layers/attention/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,25 @@ def init_cuda_graph_state(self, max_bs: int):
def init_forward_metadata_capture_cuda_graph(
self,
bs: int,
num_token: int,
req_pool_indices: torch.Tensor,
seq_lens: torch.Tensor,
encoder_lens: Optional[torch.Tensor] = None,
encoder_lens: torch.Tensor = None,
spec_info=None,
is_draft_runner=False,
):
"""Init the metadata for a forward pass for capturing a cuda graph."""
raise NotImplementedError()

def init_forward_metadata_replay_cuda_graph(
self,
bs: int,
num_token: int,
req_pool_indices: torch.Tensor,
seq_lens: torch.Tensor,
seq_lens_sum: int,
encoder_lens: Optional[torch.Tensor] = None,
encoder_lens=None,
spec_info=None,
):
"""Init the metadata for a forward pass for replying a cuda graph."""
raise NotImplementedError()
Expand All @@ -54,7 +59,9 @@ def forward(
forward_batch: ForwardBatch,
):
"""Run forward on an attention layer."""
if forward_batch.forward_mode.is_decode():
if forward_batch.forward_mode.is_verify():
return self.forward_extend(q, k, v, layer, forward_batch)
elif forward_batch.forward_mode.is_decode():
return self.forward_decode(q, k, v, layer, forward_batch)
else:
return self.forward_extend(q, k, v, layer, forward_batch)
Expand Down
Loading
Loading