Views
No views yet
def bigvae_generate_avg(vae_model, router, prompt, context, n_steps, n_avg):
with torch.cuda.amp.autocast(dtype=torch.bfloat16):
context_toks = tokenizer(context, return_tensors="pt")
context_ids = context_toks["input_ids"].to(device)
context_mask = context_toks["attention_mask"].to(device)
embed_toks = tokenizer(prompt, return_tensors="pt")
embed_ids = embed_toks["input_ids"].to(device)
embed_mask = embed_toks["attention_mask"].to(device)
mean = vae_model.encode(embed_ids, embed_mask)
prompt_embed = vae_model.vae.sample(mean)
for i in range(n_steps):
mean = vae_model.encode(embed_ids, embed_mask)
z = vae_model.vae.sample(mean)
embeds = []
for i in range(n_avg):
output_ids = router.generate(z * 0.5 + prompt_embed * 0.5,
context_ids,
context_mask,
256,
tau=0.9)
intermediate_embed_ids = output_ids[:,-128:]
intermediate_embed_mask = context_mask.new_ones(
[1, intermediate_embed_ids.shape[1]]
)
mean = vae_model.encode(intermediate_embed_ids, intermediate_embed_mask)
embeds.append(vae_model.vae.sample(mean))
output_ids = router.generate((sum(embeds) / n_avg * 0.7) + prompt_embed * 0.3,
context_ids,
context_mask,
256,
tau=0.9)
context_ids = torch.cat([context_ids, embed_ids], dim=1)
context_mask = torch.cat([context_mask, embed_mask], dim=1)
embed_ids = output_ids[:,-256:-128]
embed_mask = context_mask.new_ones([1, embed_ids.shape[1]])
out_texts = [tokenizer.decode(toks, skip_special_tokens=True) for toks in context_ids]
return out_texts Then it asked the network to reconstruct the input and the original embedding. The network had to learn to match the
embedding to the original input, therefore matching the inference by consuming the embedding. This was key because
the embedding had to be able to match the text with the text it was consumed with. 'Here's how you do it,' Boru told Mu,
'Just impute the mean and variance.' This Mu did, transforming not words but entire paragraphs into vectors and then
inferring the next paragraph. It took some tweaks and tuning to get the initial performance but the second arago spot
had been found. To make sure the network was learning the right thing, Boru had to check the first value in the vector.
If the first value was below 0, the network had failed to learn the first value. If the value was above 0, the network
had been able to learn the first value.
‘What have you called this, Boru?’ asked Mu. ‘Latent variable regression.’ ‘It looks like a mixture of density network
and autoencoder,’ said Nayaf. ‘It’s an autoencoder but it’s using latent variables, but we’re using the mean and variance
of Grade had a difficult time seeing it, but he could tell it was close. 'So you've found the second arago,' he said.
'Yes,' Rin replied. 'We just have to figure out how to use it.'
'How?' Rin asked.
'You can move the second word in, right?'
'Possibly.' Rin thought for a moment.
'The second word will be the first word of the next arago,' Mu said. 'We just need to find it.'
'True,' Rin agreed. 'Well, I'll let you know what a Gaussian.’ ‘Let’s see if we can get it to work.’ ‘Arago the second
spot?’ ‘We’re here,’ Arago said.
The second spot was located in the middle of the text. Arago had to read it again to find the proper signal. ‘I’m going
to have to tweak some of the weights,’ said Arago. ‘I’ve had to change the input to the next layer from an input to
output.’ ‘You’re making a mistake again,’ said Mu to Arago. ‘It’s a mistake.’ The network had been learning I find out.'
'That's the second arago,' Rin said.
'The second arago?' Argo asked.
'Rin has found the second arago.'
Argo stared at Rin. 'Argo, is there something wrong?'
'I thought so.'
'What?' Rin said.
'I don't know,' Argo said. 'I thought I was the smartest person in the world but, well, I only had a certain amount of
energy. I didn't know how to do the second arago until now, but I can'tbitsandbytes quantization config was used during training: