File size: 3,712 Bytes
c0a2ac4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
import argparse

from openmodellab.comparison.compare import generate_comparison
from openmodellab.comparison.table import print_table

from openmodellab.genome.model_loader import load_model
from openmodellab.genome.analyzer import analyze_model

from openmodellab.benchmark import analyze_benchmark

from openmodellab.reporting.json_writer import save_json
from openmodellab.reporting.benchmark_writer import save_benchmark
from openmodellab.reporting.csv_writer import save_csv
from openmodellab.reporting.html_writer import save_html

from openmodellab.visualization.charts import (
    save_latency_chart,
    save_throughput_chart
)


def main():

    parser = argparse.ArgumentParser(
        prog="openmodellab",
        description="OpenModelLab - Model Genome Generator"
    )

    subparsers = parser.add_subparsers(
        dest="command"
    )


    # Genome command
    genome = subparsers.add_parser(
        "genome",
        help="Generate a model genome report"
    )

    genome.add_argument(
        "--model",
        required=True,
        help="Hugging Face model name"
    )


    # Compare command
    compare = subparsers.add_parser(
        "compare",
        help="Compare model reports"
    )

    compare.add_argument(
        "--reports",
        required=True,
        help="Directory containing genome and benchmark reports"
    )

    compare.add_argument(
        "--format",
        choices=[
            "table",
            "csv",
            "html",
            "charts"
        ],
        default="table",
        help="Output format"
    )


    args = parser.parse_args()


    if args.command == "genome":

        print("=" * 60)
        print("OpenModelLab Genome")
        print("=" * 60)

        model, tokenizer = load_model(
            args.model
        )


        genome_report = analyze_model(
            args.model,
            model,
            tokenizer
        )

        genome_file = save_json(
            genome_report,
            args.model
        )


        benchmark_report = analyze_benchmark(
            model,
            tokenizer
        )

        benchmark_file = save_benchmark(
            benchmark_report,
            args.model
        )


        print()
        print("Genome report saved:")
        print(genome_file)

        print()
        print("Benchmark report saved:")
        print(benchmark_file)



    elif args.command == "compare":

        print("=" * 60)
        print("OpenModelLab Model Comparison")
        print("=" * 60)


        results = generate_comparison(
            args.reports
        )


        if args.format == "table":

            print_table(
                results
            )


        elif args.format == "csv":

            outfile = save_csv(
                results,
                "comparison_report.csv"
            )

            print()
            print("CSV report saved:")
            print(outfile)



        elif args.format == "html":

            outfile = save_html(
                results,
                "comparison_report.html"
            )

            print()
            print("HTML report saved:")
            print(outfile)



        elif args.format == "charts":

            latency_file = "latency_comparison.png"
            throughput_file = "throughput_comparison.png"


            save_latency_chart(
                results,
                latency_file
            )

            save_throughput_chart(
                results,
                throughput_file
            )


            print()
            print("Charts generated:")
            print(latency_file)
            print(throughput_file)



if __name__ == "__main__":
    main()