utils_1.py
def sample(model, x, steps, temperature=1.0, sample=False, top_k=None, prop = None, scaffold = None):
    """
    take a conditioning sequence of indices in x (of shape (b,t)) and predict the next token in
    the sequence, feeding the predictions back into the model each time. Clearly the sampling
    has quadratic complexity unlike an RNN that is only linear, and has a finite context window
    of block_size, unlike an RNN that has an infinite context window.
    """
    block_size = model.get_block_size()
    model.eval()
    
    for k in range(steps): #54
    
        x_cond = x if x.size(1) <= block_size else x[:, -block_size:] 
        
        logits, _, _ = model(x_cond, prop = prop, scaffold = scaffold)
        
        # pluck the logits at the final step and scale by temperature
        logits = logits[:, -1, :] / temperature
        
        if top_k is not None:
            
            logits = top_k_logits(logits, top_k)
        
        probs = F.softmax(logits, dim=-1)
        
        if sample:
            ix = torch.multinomial(probs, num_samples=1)
            
            _, iy = torch.topk(probs, k=1, dim=-1)
            
        else:
            _, ix = torch.topk(probs, k=1, dim=-1)
        
        x = torch.cat((x, ix), dim=1)
        
    return x

    take a conditioning sequence of indices in x (of shape (b,t)) and predict the next token in
    the sequence, feeding the predictions back into the model each time. Clearly the sampling
    has quadratic complexity unlike an RNN that is only linear, and has a finite context window
    of block_size, unlike an RNN that has an infinite context window.
    
take a conditioning sequence of indices in x (of shape (b,t)) and predict the next token in
the sequence, feeding the predictions back into the model each time. Clearly the sampling
has quadratic complexity unlike an RNN that is only linear, and has a finite context window
of block_size, unlike an RNN that has an infinite context window.
take a conditioning sequence of indices in x ( of shape ( b t )) and predict the next token in the sequence feeding the predictions back into the model each time . Clearly the sampling has quadratic complexity unlike an RNN that is only linear and has a finite context window of block_size unlike an RNN that has an infinite context window .
def sample(model, x, steps, temperature=1.0, sample=False, top_k=None, prop = None, scaffold = None):
    block_size = model.get_block_size()
    model.eval()
    for k in range(steps): 
        x_cond = x if x.size(1) <= block_size else x[:, -block_size:] 
        logits, _, _ = model(x_cond, prop = prop, scaffold = scaffold)
        logits = logits[:, -1, :] / temperature
        if top_k is not None:
            logits = top_k_logits(logits, top_k)
        probs = F.softmax(logits, dim=-1)
        if sample:
            ix = torch.multinomial(probs, num_samples=1)
            _, iy = torch.topk(probs, k=1, dim=-1)
        else:
            _, ix = torch.topk(probs, k=1, dim=-1)
        x = torch.cat((x, ix), dim=1)
    return x
def sample ( model , x , steps , temperature = 1.0 , sample = False , top_k = None , prop = None , scaffold = None ) : block_size = model . get_block_size ( ) model . eval ( ) for k in range ( steps ) : x_cond = x if x . size ( 1 ) <= block_size else x [ : , - block_size : ] logits , _ , _ = model ( x_cond , prop = prop , scaffold = scaffold ) logits = logits [ : , - 1 , : ] / temperature if top_k is not None : logits = top_k_logits ( logits , top_k ) probs = F . softmax ( logits , dim = - 1 ) if sample : ix = torch . multinomial ( probs , num_samples = 1 ) _ , iy = torch . topk ( probs , k = 1 , dim = - 1 ) else : _ , ix = torch . topk ( probs , k = 1 , dim = - 1 ) x = torch . cat ( ( x , ix ) , dim = 1 ) return x
take a conditioning sequence of indices in x (of shape (b,t)) and predict the next token in
the sequence, feeding the predictions back into the model each time.
take a conditioning sequence of indices in x ( of shape ( b t )) and predict the next token in the sequence feeding the predictions back into the model each time .
"""
    take a conditioning sequence of indices in x (of shape (b,t)) and predict the next token in
    the sequence, feeding the predictions back into the model each time. Clearly the sampling
    has quadratic complexity unlike an RNN that is only linear, and has a finite context window
    of block_size, unlike an RNN that has an infinite context window.
    """ #54 # pluck the logits at the final step and scale by temperature
model
x
steps
temperature
sample
top_k
prop
scaffold