MCPcopy Create free account
hub / github.com/TencentARC/AnimeGamer / sampling_main

Function sampling_main

inference_Decoder.py:161–265  ·  view source on GitHub ↗
(args, model_cls)

Source from the content-addressed store, hash-verified

159
160
161def sampling_main(args, model_cls):
162 decord.bridge.set_bridge("torch")
163 if isinstance(model_cls, type):
164 model = get_model(args, model_cls)
165 else:
166 model = model_cls
167
168 load_checkpoint(model, args)
169 model.eval()
170
171 if args.input_type == "cli":
172 data_iter = read_from_cli()
173 elif args.input_type == "txt":
174 rank, world_size = mpu.get_data_parallel_rank(), mpu.get_data_parallel_world_size()
175 print("rank and world_size", rank, world_size)
176 data_iter = read_from_file(args.input_file, rank=rank, world_size=world_size)
177 else:
178 raise NotImplementedError
179
180 image_size = [480, 720]
181
182 if args.image2video:
183 chained_trainsforms = []
184 chained_trainsforms.append(TT.ToTensor())
185 transform = TT.Compose(chained_trainsforms)
186
187 sample_func = model.sample
188 T, H, W, C, F = args.sampling_num_frames, image_size[0], image_size[1], args.latent_channels, 8
189 num_samples = [1]
190 force_uc_zero_embeddings = ["txt"]
191 device = model.device
192
193 ARresult = torch.load(args.LLM_output_path)
194
195 with torch.no_grad():
196 for key, value in ARresult.items():
197 count = key.split('_turn_')[0][3:]
198 batch = {'txt': ['']}
199 batch_uc = {'txt': ['']}
200
201 c, uc = model.conditioner.get_unconditional_conditioning(
202 batch, # {'txt': ['bala bala']}
203 batch_uc=batch_uc, # {'txt': ['']}
204 force_uc_zero_embeddings=force_uc_zero_embeddings,
205 )
206
207 for k in c:
208 if not k == "crossattn":
209 c[k], uc[k] = map(lambda y: y[k][: math.prod(num_samples)].to("cuda"), (c, uc))
210
211 c['ip_cond'] = torch.zeros((1, 196, 768)).type(torch.float16).cuda()
212 uc['ip_cond'] = torch.zeros_like(c['ip_cond'])
213
214 c['face_id_cond'] = torch.zeros_like(c['ip_cond'])
215 uc['face_id_cond'] = torch.zeros_like(c['ip_cond'])
216 flow_number = cuculate_level(int(value[2][0]))
217 for index in [flow_number]:
218 model.to(device)

Callers 1

Calls 8

get_modelFunction · 0.90
loadMethod · 0.80
read_from_cliFunction · 0.70
read_from_fileFunction · 0.70
cuculate_levelFunction · 0.70
decodeMethod · 0.45

Tested by

no test coverage detected