MCPcopy Create free account
hub / github.com/ZinYY/TreeLoRA / decoder_call

Method decoder_call

utils/data/data_collator.py:62–135  ·  view source on GitHub ↗
(self, batch, return_tensors)

Source from the content-addressed store, hash-verified

60
61 # support decoder-only models for left padding
62 def decoder_call(self, batch, return_tensors):
63 # to fix the bug
64 sources = []
65 gts = []
66 tokenized_sources = []
67 label_lens = []
68 actual_max_len = 0
69 limit_len = self.max_prompt_len + self.max_ans_len if not self.inference else self.max_prompt_len
70
71 for instance in batch:
72 instruction = instance['prompt']
73 label = instance['answer']
74 sources.append(instruction)
75 gts.append(label)
76
77 if not self.inference:
78 tokenized_label = self.tokenize(label, limit_len, add_bos_token=False, add_eos_token=True)
79 tokenize_source = self.tokenize(instruction + label, limit_len, add_bos_token=True, add_eos_token=True)
80 label_lens.append(len(tokenized_label["input_ids"]))
81 tokenized_sources.append(tokenize_source)
82 else:
83 if self.demonstrations!=None:
84 task_prompt = ""
85 task_prompt += TASK_PROMT[self.task]
86 if self.task!="MeetingBank":
87 task_prompt += Constrained_PROMPT
88 for demonstration in self.demonstrations:
89 if self.task=="Py150":
90 task_prompt+= "Code:\n"
91 task_prompt+=demonstration["prompt"]
92 task_prompt+=demonstration["answer"]+"\n\n"
93
94 if self.task=="Py150":
95 task_prompt+= "Code:\n"
96 # task_prompt += Constrained_PROMPT
97 if self.task!="Py150":
98 instruction = instruction[len(TASK_PROMT[self.task]):]
99 instruction = task_prompt+instruction
100 tokenize_source = self.tokenize(instruction, limit_len, add_bos_token=True, add_eos_token=False)
101 tokenized_sources.append(tokenize_source)
102
103 if len(tokenize_source["input_ids"]) > actual_max_len:
104 actual_max_len = len(tokenize_source["input_ids"])
105
106 actual_pad_len = (
107 (actual_max_len + self.pad_to_multiple_of - 1) // self.pad_to_multiple_of * self.pad_to_multiple_of)
108
109 for idx in range(len(tokenized_sources)):
110 pad_len = actual_pad_len - len(tokenized_sources[idx]["input_ids"])
111 assert sum(tokenized_sources[idx]["attention_mask"]) == len(tokenized_sources[idx]["input_ids"])
112 tokenized_sources[idx]["input_ids"] = [self.tokenizer.pad_token_id] * pad_len + tokenized_sources[idx][
113 "input_ids"]
114
115 tokenized_sources[idx]["attention_mask"] = [0] * pad_len + tokenized_sources[idx]["attention_mask"]
116
117 if not self.inference:
118 label_len = label_lens[idx]
119 label_mask_len = actual_pad_len - label_len

Callers 1

__call__Method · 0.95

Calls 1

tokenizeMethod · 0.95

Tested by

no test coverage detected