Skip to content
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
9 changes: 4 additions & 5 deletions gradio/inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,11 +221,10 @@ def inference_patch(period, composer, instrumentation):
with torch.inference_mode():

while True:
with torch.autocast(device_type='cuda', dtype=torch.float16):
predicted_patch = model.generate(input_patches.unsqueeze(0),
top_k=TOP_K,
top_p=TOP_P,
temperature=TEMPERATURE)
predicted_patch = model.generate(input_patches.unsqueeze(0),
top_k=TOP_K,
top_p=TOP_P,
temperature=TEMPERATURE)
if not tunebody_flag and patchilizer.decode([predicted_patch]).startswith('[r:'): # 初次进入tunebody,必须以[r:0/开头
tunebody_flag = True
r0_patch = torch.tensor([ord(c) for c in '[r:0/']).unsqueeze(0).to(device)
Expand Down
4 changes: 3 additions & 1 deletion gradio/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ def forward(self,

return output

@torch.no_grad()
def generate(self,
encoded_patch: torch.Tensor, # [hidden_size]
tokens: torch.Tensor): # [1]
Expand Down Expand Up @@ -379,7 +380,8 @@ def forward(self,
patches = patches[masks == 1]

return self.char_level_decoder(encoded_patches, patches)


@torch.no_grad()
def generate(self,
patches: torch.Tensor,
top_k=0,
Expand Down
4 changes: 3 additions & 1 deletion inference/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ def forward(self,

return output

@torch.no_grad()
def generate(self,
encoded_patch: torch.Tensor, # [hidden_size]
tokens: torch.Tensor): # [1]
Expand Down Expand Up @@ -379,7 +380,8 @@ def forward(self,
patches = patches[masks == 1]

return self.char_level_decoder(encoded_patches, patches)


@torch.no_grad()
def generate(self,
patches: torch.Tensor,
top_k=0,
Expand Down