File size: 2,343 Bytes
07423df
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import argparse
import logging
import os
import sys

from llm_studio.app_utils import hugging_face_utils
from llm_studio.app_utils.utils import hf_repo_friendly_name

if __name__ == "__main__":
    parser = argparse.ArgumentParser(description="")
    parser.add_argument(
        "-p",
        "--path_to_experiment",
        required=True,
        help="Path to the experiment data",
        default=argparse.SUPPRESS,
    )

    parser.add_argument(
        "-d",
        "--device",
        required=False,
        help="'cpu' or 'cuda:0', if the GPU device id is 0",
        default="cuda:0",
    )

    parser.add_argument(
        "-a",
        "--api_key",
        required=False,
        help="Hugging Face API Key",
        default=argparse.SUPPRESS,
    )

    parser.add_argument(
        "-u",
        "--user_id",
        required=False,
        help="Hugging Face User ID",
        default=argparse.SUPPRESS,
    )

    parser.add_argument(
        "-m",
        "--model_name",
        required=False,
        help="Hugging Face Model Name",
        default=argparse.SUPPRESS,
    )

    parser.add_argument(
        "-s",
        "--safe_serialization",
        required=False,
        help="A flag indicating whether safe serialization should be used.",
        default=True,
    )

    parser_args, unknown = parser.parse_known_args(sys.argv)

    path_to_experiment = parser_args.path_to_experiment
    device = parser_args.device
    safe_serialization = parser_args.safe_serialization

    api_key = getattr(parser_args, "api_key", "")
    user_id = getattr(parser_args, "user_id", "")
    model_name = getattr(parser_args, "model_name", "")

    # If the model_name argument is not provided,
    # the function derives a model name from the last folder name
    if model_name == "":
        path_to_experiment = path_to_experiment.rstrip("/")
        model_name = hf_repo_friendly_name(os.path.basename(path_to_experiment))

    try:
        hugging_face_utils.publish_model_to_hugging_face(
            path_to_experiment=path_to_experiment,
            device=device,
            api_key=api_key,
            user_id=user_id,
            model_name=model_name,
            safe_serialization=safe_serialization,
        )
    except Exception:
        logging.error("Exception occurred during the run:", exc_info=True)