Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/kaggle-gguf-on-tmp #1307

Draft
wants to merge 5 commits into
base: nightly
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion unsloth/models/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ def from_pretrained(
exist_config = os.path.exists(os.path.join(model_name, "config.json"))
both_exist = exist_adapter_config and exist_config
else:
files = HfFileSystem(token = token).glob(os.path.join(model_name, "*.json"))
files = HfFileSystem(token = token).glob(f"{model_name}/*.json")
files = (os.path.split(x)[-1] for x in files)
if sum(x == "adapter_config.json" or x == "config.json" for x in files) >= 2:
both_exist = True
Expand Down
33 changes: 30 additions & 3 deletions unsloth/save.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ def unsloth_save_model(
print("Saved to https://huggingface.co/" + save_pretrained_settings["save_directory"])
pass

print(" Done.")
print(" Done. Model were saved at " + save_pretrained_settings["save_directory"])
return save_directory, None
pass

Expand Down Expand Up @@ -1120,7 +1120,7 @@ def save_to_gguf(
# Check if quantization succeeded!
if not os.path.isfile(final_location):
if IS_KAGGLE_ENVIRONMENT:
if not Path(final_location).resolve().is_relative_to(Path('/tmp').resolve()):
if not Path(final_location).resolve().is_relative_to(Path(KAGGLE_TMP).resolve()):
raise RuntimeError(
f"Unsloth: Quantization failed for {final_location}\n"\
"You are in a Kaggle environment, which might be the reason this is failing.\n"\
Expand Down Expand Up @@ -1171,7 +1171,7 @@ def save_to_gguf(
# Check if quantization succeeded!
if not os.path.isfile(final_location):
if IS_KAGGLE_ENVIRONMENT:
if not Path(final_location).resolve().is_relative_to(Path('/tmp').resolve()):
if not Path(final_location).resolve().is_relative_to(Path(KAGGLE_TMP).resolve()):
raise RuntimeError(
f"Unsloth: Quantization failed for {final_location}\n"\
"You are in a Kaggle environment, which might be the reason this is failing.\n"\
Expand Down Expand Up @@ -1612,6 +1612,9 @@ def unsloth_save_pretrained_gguf(
del arguments["quantization_method"]
del arguments["first_conversion"]

if IS_KAGGLE_ENVIRONMENT:
arguments["save_directory"] = os.path.join(KAGGLE_TMP, save_directory)

# Fix tokenizer adding an extra BOS token at the front
fix_bos_token, old_chat_template = fix_tokenizer_bos_token(tokenizer)

Expand Down Expand Up @@ -1703,6 +1706,19 @@ def unsloth_save_pretrained_gguf(
)
pass

if IS_KAGGLE_ENVIRONMENT:
list_of_files = list(all_file_locations)
if modelfile_location is not None:
list_of_files.append(modelfile_location)

from IPython.display import FileLink, display

for file_location in list_of_files:
if file_location is not None:
display(FileLink(file_location))

logger.info("Unsloth: Click the above links to download the files.")

if push_to_hub:
print("Unsloth: Uploading GGUF to Huggingface Hub...")

Expand Down Expand Up @@ -1790,6 +1806,9 @@ def unsloth_push_to_hub_gguf(
del arguments["quantization_method"]
del arguments["first_conversion"]

if IS_KAGGLE_ENVIRONMENT:
arguments["save_directory"] = os.path.join(KAGGLE_TMP, arguments["save_directory"])

# Fix tokenizer adding an extra BOS token at the front
fix_bos_token, old_chat_template = fix_tokenizer_bos_token(tokenizer)

Expand Down Expand Up @@ -1887,6 +1906,10 @@ def unsloth_push_to_hub_gguf(
if username not in new_save_directory else \
new_save_directory.lstrip('/.')

if IS_KAGGLE_ENVIRONMENT:
# Take last 2 parts of the link
link = "/".join(link.split("/")[-2:])

print(f"Saved GGUF to https://huggingface.co/{link}")
pass

Expand All @@ -1896,6 +1919,10 @@ def unsloth_push_to_hub_gguf(
self, repo_id, token,
"GGUF converted", "gguf", modelfile_location, old_username, private,
)
if IS_KAGGLE_ENVIRONMENT:
# Take last 2 parts of the link
link = "/".join(link.split("/")[-2:])

print(f"Saved Ollama Modelfile to https://huggingface.co/{link}")
pass

Expand Down