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
def setattrattr(cfg, k, v): | |
""" | |
Sets an attr even it's like o.a.b | |
Usage: | |
setattrattr(obj, 'loss.alpha', 0.1) | |
https://gist.github.com/wassname/33ef989ab06325daeeef68be1d638a2c/edit | |
""" | |
if '.' in k: |
We can make this file beautiful and searchable if this error is corrected: It looks like row 5 should actually have 24 columns, instead of 8 in line 4.
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
Book Id,Title,Author,Author l-f,Additional Authors,ISBN,ISBN13,My Rating,Average Rating,Publisher,Binding,Number of Pages,Year Published,Original Publication Year,Date Read,Date Added,Bookshelves,Bookshelves with positions,Exclusive Shelf,My Review,Spoiler,Private Notes,Read Count,Owned Copies | |
60233239,"The Butcher's Masquerade (Dungeon Crawler Carl, #5)",Matt Dinniman,"Dinniman, Matt",,"=""""","=""""",5,4.68,Dandy House,Kindle Edition,726,2022,2022,,2024/08/27,,,read,,,,1,0 | |
12913718,"달빛 조각사 1 (The Legendary Moonlight Sculptor, #1)",Heesung Nam,"Nam, Heesung",,"=""895857903X""","=""9788958579038""",4,4.38,로크미디어,Paperback,344,2007,2007,,2016/11/14,"favs, 5star","favs (#37), 5star (#132)",read,,,,1,0 | |
18527310,"달빛 조각사 4 (The Legendary Moonlight Sculptor, #4)",Heesung Nam,"Nam, Heesung",,"=""8958579064""","=""9788958579062""",4,4.38,로크미디어,Paperback,335,2007,2007,,2024/08/27,,,read,,,,1,0 | |
17661892,"달빛 조각사 2 (The Legendary Moonlight Sculptor, #2)",Heesung Nam,"Nam, Heesung",,"=""8958579048""","=""9788958579045""",4 |
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
from lightning.pytorch.callbacks import ModelCheckpoint | |
from weakref import proxy | |
class AdapterModelCheckpoint(ModelCheckpoint): | |
def _save_checkpoint(self, trainer: "pl.Trainer", filepath: str) -> None: | |
trainer.model.save_pretrained(filepath) | |
# trainer.save_checkpoint(filepath, self.save_weights_only) | |
self._last_global_step_saved = trainer.global_step | |
self._last_checkpoint_saved = filepath |
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
# # FIXME DOT NOT USE | |
# # upon further investigation, it seems the bnb will handle conversion as long as you use bloat16 of float32, float16 | |
# from lightning.pytorch.plugins.precision.precision import Precision | |
# from lightning.fabric.plugins.precision.utils import ( | |
# _ClassReplacementContextManager, | |
# _convert_fp_tensor, | |
# _DtypeContextManager, | |
# ) | |
# from typing_extensions import Self, override |
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
from peft.peft_model import BaseTunerLayer, PeftModel | |
from peft.utils.other import ModulesToSaveWrapper | |
def adapter_is_disabled(model: PeftModel) -> bool: | |
"""Given a peft model work out is adapters are enabled or disabled""" | |
for module in model.model.modules(): | |
if isinstance(module, (BaseTunerLayer, ModulesToSaveWrapper)): | |
# print(help(module.enable_adapters)) | |
return module._disable_adapters |
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 sympy as sp | |
from typing import Dict, Any | |
from IPython.display import display | |
from sympy import init_printing | |
init_printing() | |
def shypothesis(hypothesis: str, variables: Dict[str, Any] = None, round=3, verbose=False): | |
""" | |
Evaluate a hypothesis using SymPy, showing simplified equation and result. |
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
""" | |
craftax = "1.4.1" | |
jax = "^0.4.28" | |
jax = | |
https://gist.github.com/wassname/9f410d11f33cec75393b64d62286dd41 | |
""" | |
import numpy as np | |
import numpy as np | |
from craftax.craftax.craftax_state import EnvState, Inventory, Mobs | |
from craftax.craftax.constants import MAX_OBS_DIM, OBS_DIM, BlockType, ItemType, MONSTERS_KILLED_TO_CLEAR_LEVEL |
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
{ | |
// Use IntelliSense to learn about possible attributes. | |
// Hover to view descriptions of existing attributes. | |
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | |
"version": "0.2.0", | |
"configurations": [ | |
{ | |
"name": "test", | |
"type": "debugpy", | |
"request": "launch", |
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
from jaxtyping import Float, Int | |
import torch | |
from torch.nn import functional as F | |
from torch import Tensor | |
from typing import List, Callable, Tuple, Dict, Optional | |
import pandas as pd | |
from transformers import AutoModelForCausalLM, AutoTokenizer | |
def get_valid_next_choices(choices_tokens, current_tokens): |
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
# Directly taken from https://huggingface.co/spaces/evaluate-measurement/perplexity/blob/main/perplexity.py | |
# TODO replace with a strided version https://github.com/huggingface/transformers/issues/9648#issuecomment-812981524 | |
import numpy as np | |
import torch | |
import itertools | |
from torch.nn import CrossEntropyLoss | |
from tqdm.auto import tqdm | |
import torch.nn.functional as F | |
from datasets import load_dataset, Dataset | |
from transformers import AutoTokenizer, AutoModelForCausalLM |
NewerOlder