gpt-neox
1# Copyright (c) 2024, EleutherAI
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15import os16import sys17
18from huggingface_hub import HfApi, create_repo19
20converted_ckpt = sys.argv[1]21repo_name = sys.argv[2]22branch_name = sys.argv[3]23try:24create_repo(repo_name, repo_type="model", private=False)25except:26print("repo {repo_name} already exists!")27pass28
29files = os.listdir(converted_ckpt)30
31api = HfApi()32if branch_name != "main":33try:34api.create_branch(35repo_id=repo_name,36repo_type="model",37branch=branch_name,38)39except:40print(f"branch {branch_name} already exists, try again...")41print(f"to upload: {files}")42for file in files:43print(f"Uploading {file} to branch {branch_name}...")44api.upload_file(45path_or_fileobj=os.path.join(converted_ckpt, file),46path_in_repo=file,47repo_id=repo_name,48repo_type="model",49commit_message=f"Upload {file}",50revision=branch_name,51)52print(f"Successfully uploaded {file} !")53