Skip to content

Commit

Permalink
update all references
Browse files Browse the repository at this point in the history
  • Loading branch information
yczhang-nv committed Dec 5, 2024
1 parent 68c4d06 commit 0fb7a57
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 27 deletions.
24 changes: 12 additions & 12 deletions examples/log_parsing/inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,16 @@ class TritonInferenceLogParsing(TritonInferenceWorker):
"""

def build_output_message(self, msg: ControlMessage) -> ControlMessage:
seq_ids = cp.zeros((msg.tensors().count, 3), dtype=cp.uint32)
seq_ids[:, 0] = cp.arange(0, msg.tensors().count, dtype=cp.uint32)
seq_ids = cp.zeros((msg.tensor_count(), 3), dtype=cp.uint32)
seq_ids[:, 0] = cp.arange(0, msg.tensor_count(), dtype=cp.uint32)
seq_ids[:, 2] = msg.tensors().get_tensor('seq_ids')[:, 2]

memory = TensorMemory(
count=msg.tensors().count,
count=msg.tensor_count(),
tensors={
'confidences': cp.zeros((msg.tensors().count, self._inputs[list(self._inputs.keys())[0]].shape[1])),
'labels': cp.zeros((msg.tensors().count, self._inputs[list(self._inputs.keys())[0]].shape[1])),
'input_ids': cp.zeros((msg.tensors().count, msg.tensors().get_tensor('input_ids').shape[1])),
'confidences': cp.zeros((msg.tensor_count(), self._inputs[list(self._inputs.keys())[0]].shape[1])),
'labels': cp.zeros((msg.tensor_count(), self._inputs[list(self._inputs.keys())[0]].shape[1])),
'input_ids': cp.zeros((msg.tensor_count(), msg.tensors().get_tensor('input_ids').shape[1])),
'seq_ids': seq_ids
})

Expand Down Expand Up @@ -154,19 +154,19 @@ def _convert_one_response(output: ControlMessage, inf: ControlMessage, res: Tens
seq_offset = seq_ids[0, 0].item()
seq_count = seq_ids[-1, 0].item() + 1 - seq_offset

input_ids[batch_offset:inf.tensors().count + batch_offset, :] = inf.tensors().get_tensor('input_ids')
out_seq_ids[batch_offset:inf.tensors().count + batch_offset, :] = seq_ids
input_ids[batch_offset:inf.tensor_count() + batch_offset, :] = inf.tensors().get_tensor('input_ids')
out_seq_ids[batch_offset:inf.tensor_count() + batch_offset, :] = seq_ids

resp_confidences = res.get_tensor('confidences')
resp_labels = res.get_tensor('labels')

# Two scenarios:
if (inf.payload().count == inf.tensors().count):
if (inf.payload().count == inf.tensor_count()):
assert seq_count == res.count
confidences[batch_offset:inf.tensors().count + batch_offset, :] = resp_confidences
labels[batch_offset:inf.tensors().count + batch_offset, :] = resp_labels
confidences[batch_offset:inf.tensor_count() + batch_offset, :] = resp_confidences
labels[batch_offset:inf.tensor_count() + batch_offset, :] = resp_labels
else:
assert inf.tensors().count == res.count
assert inf.tensor_count() == res.count

mess_ids = seq_ids[:, 0].get().tolist()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ static ShapeType get_seq_ids(const std::shared_ptr<ControlMessage>& message)
auto seq_ids = message->tensors()->get_tensor("seq_ids");
const auto item_size = seq_ids.dtype().item_size();

ShapeType host_seq_ids(message->tensors()->count);
ShapeType host_seq_ids(message->tensor_count());
MRC_CHECK_CUDA(cudaMemcpy2D(host_seq_ids.data(),
item_size,
seq_ids.data(),
Expand All @@ -82,7 +82,7 @@ static TensorObject get_tensor(std::shared_ptr<ControlMessage> message, std::str

static void reduce_outputs(std::shared_ptr<ControlMessage> const& message, TensorMap& output_tensors)
{
if (message->payload()->count() == message->tensors()->count)
if (message->payload()->count() == message->tensor_count())
{
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ def __init__(self, inf_queue: ProducerConsumerQueue, c: Config):
self._seq_length = c.feature_length

def calc_output_dims(self, msg: ControlMessage) -> typing.Tuple:
return (msg.tensors().count, self._seq_length)
return (msg.tensor_count(), self._seq_length)

def process(self, batch: ControlMessage, callback: typing.Callable[[TensorMemory], None]):

def tmp(batch: ControlMessage, f):
count = batch.tensors().count
count = batch.tensor_count()
f(TensorMemory(
count=count,
tensors={'probs': cp.zeros((count, self._seq_length), dtype=cp.float32)},
Expand Down
6 changes: 3 additions & 3 deletions python/morpheus/morpheus/stages/inference/inference_stage.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ def set_output_fut(resp: TensorMemory, inner_batch, batch_future: mrc.Future):
nonlocal outstanding_requests
nonlocal batch_offset
mess = self._convert_one_response(output_message, inner_batch, resp, batch_offset)
batch_offset += inner_batch.tensors().count
batch_offset += inner_batch.tensor_count()
outstanding_requests -= 1

batch_future.set_result(mess)
Expand Down Expand Up @@ -359,13 +359,13 @@ def _convert_one_response(output: ControlMessage, inf: ControlMessage, res: Tens
seq_count = seq_ids[-1, 0].item() + 1 - seq_offset

# Two scenarios:
if (inf.payload().count == inf.tensors().count):
if (inf.payload().count == inf.tensor_count()):
assert seq_count == res.count

# In message and out message have same count. Just use probs as is
probs[seq_offset:seq_offset + seq_count, :] = resp_probs
else:
assert inf.tensors().count == res.count
assert inf.tensor_count() == res.count

mess_ids = seq_ids[:, 0].get().tolist()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def init(self):
def calc_output_dims(self, msg: ControlMessage) -> typing.Tuple:
input_ids = msg.tensors().get_tensor("input_ids")
input_mask = msg.tensors().get_tensor("input_mask")
count = msg.tensors().count
count = msg.tensor_count()
# If we haven't cached the output dimension, do that here
if (not self._output_size):
test_intput_ids_shape = (self._max_batch_size, ) + input_ids.shape[1:]
Expand All @@ -91,7 +91,7 @@ def calc_output_dims(self, msg: ControlMessage) -> typing.Tuple:
def process(self, batch: ControlMessage, callback: typing.Callable[[TensorMemory], None]):
input_ids = batch.tensors().get_tensor("input_ids")
input_mask = batch.tensors().get_tensor("input_mask")
count = batch.tensors().count
count = batch.tensor_count()

# convert from cupy to torch tensor using dlpack
input_ids = from_dlpack(input_ids.astype(cp.float).toDlpack()).type(torch.long)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@ def create_wrapper():
raise ex

def calc_output_dims(self, msg: ControlMessage) -> typing.Tuple:
return (msg.tensors().count, self._outputs[list(self._outputs.keys())[0]].shape[1])
return (msg.tensor_count(), self._outputs[list(self._outputs.keys())[0]].shape[1])

def _build_response(
self,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def _calc_drift(self, msg: ControlMessage):
for label in range(len(self._labels), shifted.shape[1]):
self._labels.append(str(label))

count = msg.tensors().count
count = msg.tensor_count()

for i in list(range(0, count, self._batch_size)):
start = i
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def check_inf_message(msg: ControlMessage,
expected_input__0: cp.ndarray):
assert isinstance(msg, ControlMessage)
assert msg.payload().count == expected_mess_count
assert msg.tensors().count == expected_count
assert msg.tensor_count() == expected_count

df = msg.payload().get_data()
assert 'flow_id' in df
Expand Down
4 changes: 2 additions & 2 deletions tests/examples/log_parsing/test_inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def test_log_parsing_triton_inference_log_parsing_build_output_message(config: C
msg = worker.build_output_message(input_msg)
assert msg.payload() is input_msg.payload()
assert msg.payload().count == mess_count
assert msg.tensors().count == count
assert msg.tensor_count() == count

assert set(msg.tensors().tensor_names).issuperset(('confidences', 'labels', 'input_ids', 'seq_ids'))
assert msg.tensors().get_tensor('confidences').shape == (count, 2)
Expand Down Expand Up @@ -187,7 +187,7 @@ def test_log_parsing_inference_stage_convert_one_response(import_mod: typing.Lis
assert isinstance(output_msg, ControlMessage)
assert output_msg.payload() is input_inf.payload()
assert output_msg.payload().count == mess_count
assert output_msg.tensors().count == count
assert output_msg.tensor_count() == count

assert (output_msg.tensors().get_tensor('seq_ids') == input_inf.tensors().get_tensor('seq_ids')).all()
assert (output_msg.tensors().get_tensor('input_ids') == input_inf.tensors().get_tensor('input_ids')).all()
Expand Down
2 changes: 1 addition & 1 deletion tests/morpheus/stages/test_inference_stage.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def test_convert_one_response():
cm = InferenceStageT._convert_one_response(output, inf, res, batch_offset)
assert cm.payload() == inf.payload()
assert cm.payload().count == 4
assert cm.tensors().count == 4
assert cm.tensor_count() == 4
assert cp.all(cm.tensors().get_tensor("probs") == res.get_tensor("probs"))

# Test for the second branch
Expand Down

0 comments on commit 0fb7a57

Please sign in to comment.