Update legacy Repository usage in various example files (#29085)
* Update legacy Repository usage in `examples/pytorch/text-classification/run_glue_no_trainer.py` Marked for deprecation here https://huggingface.co/docs/huggingface_hub/guides/upload#legacy-upload-files-with-git-lfs * Fix import order * Replace all example usage of deprecated Repository * Fix remaining repo call and rename args variable * Revert removing creation of gitignore files and don't change research examples
This commit is contained in:
committed by
GitHub
parent
f1a565a39f
commit
b6404866cd
@@ -39,7 +39,7 @@ from flax import struct, traverse_util
|
||||
from flax.jax_utils import pad_shard_unpad, replicate, unreplicate
|
||||
from flax.training import train_state
|
||||
from flax.training.common_utils import get_metrics, onehot, shard
|
||||
from huggingface_hub import Repository, create_repo
|
||||
from huggingface_hub import HfApi
|
||||
from tqdm import tqdm
|
||||
|
||||
import transformers
|
||||
@@ -429,9 +429,8 @@ def main():
|
||||
if repo_name is None:
|
||||
repo_name = Path(training_args.output_dir).absolute().name
|
||||
# Create repo and retrieve repo_id
|
||||
repo_id = create_repo(repo_name, exist_ok=True, token=training_args.hub_token).repo_id
|
||||
# Clone repo locally
|
||||
repo = Repository(training_args.output_dir, clone_from=repo_id, token=training_args.hub_token)
|
||||
api = HfApi()
|
||||
repo_id = api.create_repo(repo_name, exist_ok=True, token=training_args.hub_token).repo_id
|
||||
|
||||
# Get the datasets: you can either provide your own CSV/JSON/TXT training and evaluation files (see below)
|
||||
# or just provide the name of one of the public datasets for token classification task available on the hub at https://huggingface.co/datasets/
|
||||
@@ -798,7 +797,13 @@ def main():
|
||||
model.save_pretrained(training_args.output_dir, params=params)
|
||||
tokenizer.save_pretrained(training_args.output_dir)
|
||||
if training_args.push_to_hub:
|
||||
repo.push_to_hub(commit_message=f"Saving weights and logs of step {cur_step}", blocking=False)
|
||||
api.upload_folder(
|
||||
commit_message=f"Saving weights and logs of step {cur_step}",
|
||||
folder_path=training_args.output_dir,
|
||||
repo_id=repo_id,
|
||||
repo_type="model",
|
||||
token=training_args.hub_token,
|
||||
)
|
||||
epochs.desc = f"Epoch ... {epoch + 1}/{num_epochs}"
|
||||
|
||||
# Eval after training
|
||||
|
||||
Reference in New Issue
Block a user