We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
你好,我修改了推理代码实现了batch推理,但是rnn那个部分的推理时间和batch成线性关系,请问能帮忙解释一下这个现象么,谢谢
lenText = nT nsteps = nT output = torch.zeros(nB, lenText).int() output_probs = torch.zeros(nB, lenText).float()
hidden = torch.zeros(nB, self.nchannel).type_as(C.data) stats = torch.zeros(nB, self.nchannel).type_as(C.data) prev_emb = self.char_embeddings.index_select(0, torch.zeros(nB).type_as(C.data).long())
for step in range(nsteps): hidden, stats = self.rnn(torch.cat((C[step, :, :], prev_emb), dim=1), (hidden, stats)) step_result = self.generator(hidden) step_result = F.softmax(step_result, dim=-1) max_prob_index = torch.argmax(step_result, dim=1) max_prob = step_result.index_select(dim=1, index=max_prob_index) output[:, step] = max_prob_index output_probs[:, step] = max_prob prev_emb = self.char_embeddings.index_select(0, max_prob_index.long())
return output, output_probs
The text was updated successfully, but these errors were encountered:
No branches or pull requests
你好,我修改了推理代码实现了batch推理,但是rnn那个部分的推理时间和batch成线性关系,请问能帮忙解释一下这个现象么,谢谢
lenText = nT
nsteps = nT
output = torch.zeros(nB, lenText).int()
output_probs = torch.zeros(nB, lenText).float()
hidden = torch.zeros(nB, self.nchannel).type_as(C.data)
stats = torch.zeros(nB, self.nchannel).type_as(C.data)
prev_emb = self.char_embeddings.index_select(0, torch.zeros(nB).type_as(C.data).long())
for step in range(nsteps):
hidden, stats = self.rnn(torch.cat((C[step, :, :], prev_emb), dim=1), (hidden, stats))
step_result = self.generator(hidden)
step_result = F.softmax(step_result, dim=-1)
max_prob_index = torch.argmax(step_result, dim=1)
max_prob = step_result.index_select(dim=1, index=max_prob_index)
output[:, step] = max_prob_index
output_probs[:, step] = max_prob
prev_emb = self.char_embeddings.index_select(0, max_prob_index.long())
return output, output_probs
The text was updated successfully, but these errors were encountered: