Skip to content
Merged
Changes from 1 commit
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
Next Next commit
NPU needs to be initialized when starting a new process
  • Loading branch information
jq460494839 committed Dec 21, 2023
commit ed8069edade958e68e02ce9aece06bef6567d5a4
8 changes: 5 additions & 3 deletions fastchat/serve/model_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
str_to_torch_dtype,
)


worker_id = str(uuid.uuid4())[:8]
logger = build_logger("model_worker", f"model_worker_{worker_id}.log")

Expand Down Expand Up @@ -101,6 +100,9 @@ def __init__(
self.init_heart_beat()

def generate_stream_gate(self, params):
if self.device == "npu":
import torch_npu
torch_npu.npu.set_device("npu:0")
self.call_ct += 1

try:
Expand Down Expand Up @@ -216,8 +218,8 @@ def get_embeddings(self, params):
all_embeddings = []
all_token_num = 0
for i in range(0, input_ids.size(1), self.context_len):
chunk_input_ids = input_ids[:, i : i + self.context_len]
chunk_attention_mask = attention_mask[:, i : i + self.context_len]
chunk_input_ids = input_ids[:, i: i + self.context_len]
chunk_attention_mask = attention_mask[:, i: i + self.context_len]

chunk_embeddings, token_num = self.__process_embed_chunk(
chunk_input_ids, chunk_attention_mask, **model_type_dict
Expand Down