This file contains hidden or 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 math | |
import torch | |
from torch.optim import AdamW | |
class MemoryEfficientAdamW(AdamW): | |
""" | |
Memory Efficient AdamW optimizer that keeps parameters and gradients on GPU | |
but optimizer states on CPU when enabled. |
This file contains hidden or 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
""" | |
This script converts a Hugging Face LLaMA3 model checkpoint to the original LLaMA3 checkpoint format. | |
Usage example: | |
python convert_hf_to_llama3.py --hf_model_path "path/to/hf/model" --output_path "path/to/output" | |
""" | |
import torch | |
from transformers import LlamaForCausalLM | |
import os |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or 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
''' | |
Implementation for https://arxiv.org/abs/1906.00672 | |
Tips: The code could be directly used in place of BadahnauMonotonicAttention in Tensorflow codes. Similar to its | |
base class in the Tensorflow seq2seq codebase, you may use "hard" for hard inference, or "parallel" for training or | |
soft inference. "recurrent" mode in BadahnauMonotonicAttention is not supported. | |
If you have already trained another model using BadahnauMonotonicAttention, the model could be reused, otherwise you | |
possibly have to tune the score_bias_init, which, similar to that in Raffel et al., 2017, is determined a priori to | |
suit the moving speed of the alignments, i.e. speed of speech of your training corpus in TTS cases. So |
This file contains hidden or 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
""" | |
Add mypy type-checking cell magic to jupyter/ipython. | |
Save this script to your ipython profile's startup directory. | |
IPython's directories can be found via `ipython locate [profile]` to find the current ipython directory and ipython profile directory, respectively. | |
For example, this file could exist on a path like this on mac: | |
/Users/yourusername/.ipython/profile_default/startup/typecheck.py |