This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import os | |
import sys | |
import time | |
from crontab import CronTab | |
def main(): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import torch | |
@torch.no_grad() | |
def beam_search(model, x, beam_width, output_length, block_size=None, exclude_classes=None, temperature=1): | |
""" | |
Beam search for PyTorch. | |
See `Beam search <https://en.wikipedia.org/wiki/Beam_search>`_. | |
Args: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# references: | |
# https://peterbloem.nl/blog/transformers | |
# https://github.com/karpathy/minGPT | |
# https://github.com/pytorch/pytorch/blob/main/torch/nn/modules/transformer.py | |
import math | |
import torch | |
import torch.nn as nn | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import torch | |
@torch.no_grad() | |
def sample(model, x, output_length, block_size, exclude_classes=None, temperature=1, top_k=None, top_p=None): | |
""" | |
Sampling for autoregressive models in PyTorch. | |
See `How to generate text <https://huggingface.co/blog/how-to-generate>`_. | |
Args: |