tinymlc 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. TinyMLC/ANG/__init__.py +0 -0
  2. TinyMLC/ANG/args.py +86 -0
  3. TinyMLC/ANG/estimator.py +103 -0
  4. TinyMLC/ANG/estimator_hal.py +184 -0
  5. TinyMLC/ANG/estimator_qemu.py +257 -0
  6. TinyMLC/ANG/estimator_software.py +130 -0
  7. TinyMLC/ANG/model_builder.py +508 -0
  8. TinyMLC/ANG/model_generator.py +439 -0
  9. TinyMLC/ANG/model_info.py +283 -0
  10. TinyMLC/ANG/utils.py +420 -0
  11. TinyMLC/__init__.py +0 -0
  12. TinyMLC/cli.py +126 -0
  13. TinyMLC/codegen.py +877 -0
  14. TinyMLC/converter/__init__.py +0 -0
  15. TinyMLC/converter/export_weights.py +382 -0
  16. TinyMLC/converter/parser_litert.py +757 -0
  17. TinyMLC/converter/parser_onnx.py +649 -0
  18. TinyMLC/generate_lut.py +97 -0
  19. TinyMLC/handlers.py +325 -0
  20. TinyMLC/ops.py +76 -0
  21. TinyMLC/templates/lut.c.tpl +23 -0
  22. TinyMLC/templates/lut.h.tpl +67 -0
  23. TinyMLC/templates/model.c.tpl +314 -0
  24. TinyMLC/templates/model.h.tpl +66 -0
  25. TinyMLC/transform/__init__.py +0 -0
  26. TinyMLC/transform/algebraic.py +286 -0
  27. TinyMLC/transform/base.py +58 -0
  28. TinyMLC/transform/constant_folding.py +260 -0
  29. TinyMLC/transform/cse.py +192 -0
  30. TinyMLC/transform/dce.py +182 -0
  31. TinyMLC/transform/fusion.py +723 -0
  32. TinyMLC/transform/memory.py +200 -0
  33. TinyMLC/transform/pass_manager.py +101 -0
  34. TinyMLC/transform/simplify.py +515 -0
  35. tinymlc-0.1.0.dist-info/METADATA +49 -0
  36. tinymlc-0.1.0.dist-info/RECORD +47 -0
  37. tinymlc-0.1.0.dist-info/WHEEL +4 -0
  38. tinymlc-0.1.0.dist-info/entry_points.txt +2 -0
  39. tinymlc-0.1.0.dist-info/licenses/LICENSE +201 -0
  40. utils/__init__.py +0 -0
  41. utils/arm-none-eabi-gcc.cmake +53 -0
  42. utils/dump.py +86 -0
  43. utils/generate_onnx_models.py +183 -0
  44. utils/generate_tflite_models.py +236 -0
  45. utils/pack_macos.sh +88 -0
  46. utils/path.py +31 -0
  47. utils/riscv-none-elf-gcc.cmake +50 -0
TinyMLC/cli.py ADDED
@@ -0,0 +1,126 @@
1
+ # -*- coding: utf-8 -*-
2
+ # TinyMLC - Tiny Machine Learning Compiler
3
+ #
4
+ # Copyright (c) 2026 Jia Liu & TinyMLC Contributors
5
+ # SPDX-License-Identifier: Apache-2.0
6
+ #
7
+ # This file is part of TinyMLC.
8
+ # Licensed under the Apache License, Version 2.0 (the "License");
9
+ # you may not use this file except in compliance with the License.
10
+ # You may obtain a copy of the License at:
11
+ #
12
+ # http://www.apache.org/licenses/LICENSE-2.0
13
+ #
14
+ # Unless required by applicable law or agreed to in writing, software
15
+ # distributed under the License is distributed on an "AS IS" BASIS,
16
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ # See the License for the specific language governing permissions and
18
+ # limitations under the License.
19
+
20
+ #!/usr/bin/env python3
21
+ # Entry point for TinyMLC command line interface
22
+
23
+ import argparse
24
+ import sys
25
+
26
+ from TinyMLC.handlers import handle_generate, handle_convert
27
+ from utils.dump import fatal_error
28
+ from TinyMLC.ANG.args import parse_shape
29
+
30
+
31
+ global_parent = argparse.ArgumentParser(add_help=False)
32
+ global_parent.add_argument("--verbose", "-v", action="store_true")
33
+ global_parent.add_argument(
34
+ "--target", "-t", type=str, default="riscv",
35
+ choices=["riscv", "arm", "host"]
36
+ )
37
+ global_parent.add_argument(
38
+ "--mode", type=str, default="release", choices=["debug", "release"])
39
+ global_parent.add_argument(
40
+ "--accel", type=str, default="pure-c",
41
+ choices=["cmsis-nn", "nmsis-nn", "pure-c"])
42
+ global_parent.add_argument(
43
+ "--accel-lib-inc", type=str,
44
+ help="Path to accelerator library include directory")
45
+ global_parent.add_argument(
46
+ "--accel-lib-lib", type=str, help="Path to accelerator library lib file")
47
+
48
+ global_parent.add_argument("--with-test-main", action="store_true")
49
+ global_parent.add_argument("--run", action="store_true")
50
+ global_parent.add_argument(
51
+ "--inference-function-name", type=str, default="tinymlc_inference")
52
+ global_parent.add_argument("--output-dir", type=str, default=".")
53
+ global_parent.add_argument("--dump-model", type=str)
54
+
55
+ def main() -> int:
56
+ parser = argparse.ArgumentParser(
57
+ description="TinyMLC - TinyML Compiler CLI",
58
+ parents=[global_parent],
59
+ formatter_class=argparse.RawDescriptionHelpFormatter,
60
+ )
61
+
62
+ subparsers = parser.add_subparsers(
63
+ dest="command", help="Command to execute"
64
+ )
65
+
66
+ # ---- generate ----
67
+ gen_parser = subparsers.add_parser(
68
+ "generate", parents=[global_parent], help="Generate a network"
69
+ )
70
+ gen_parser.add_argument(
71
+ "--task-type",
72
+ type=str,
73
+ default="classification",
74
+ choices=["classification", "detection", "segmentation"],
75
+ )
76
+ gen_parser.add_argument(
77
+ "--input-shape", type=parse_shape, default=[1, 28, 28, 1]
78
+ )
79
+ gen_parser.add_argument("--output-shape", type=parse_shape, default=[1, 10])
80
+ gen_parser.add_argument("--max-macs", type=int, default=100000)
81
+ gen_parser.add_argument("--max-ram", type=int, default=30)
82
+ gen_parser.add_argument("--max-flash", type=int, default=64)
83
+ gen_parser.add_argument("--clock-speed", type=int, default=100000000)
84
+ gen_parser.add_argument("--icount-shift", type=int, default=0)
85
+ gen_parser.add_argument("--qemu-cpu", type=str, default="cortex-m4")
86
+ gen_parser.add_argument(
87
+ "--estimator",
88
+ type=str,
89
+ default="software",
90
+ choices=["software", "qemu", "hardware"],
91
+ )
92
+ gen_parser.add_argument("--estimator-script", type=str)
93
+ gen_parser.add_argument(
94
+ "--estimator-function", type=str, default="estimate"
95
+ )
96
+ gen_parser.add_argument(
97
+ "--generate-mode", type=str, default="genetic",
98
+ choices=["random", "genetic"])
99
+ gen_parser.add_argument("--population", type=int, default=50)
100
+ gen_parser.add_argument("--generations", type=int, default=50)
101
+ gen_parser.add_argument("--early-stop", type=int, default=10)
102
+ gen_parser.add_argument("--num-samples", type=int, default=100)
103
+
104
+ # ---- convert ----
105
+ convert_parser = subparsers.add_parser(
106
+ "convert", parents=[global_parent], help="Convert an existing model"
107
+ )
108
+ convert_parser.add_argument("--model", type=str, required=True)
109
+
110
+ args = parser.parse_args()
111
+
112
+ if not args.command:
113
+ parser.print_help()
114
+ return 1
115
+
116
+ if args.command == "generate":
117
+ return handle_generate(args)
118
+ elif args.command == "convert":
119
+ return handle_convert(args)
120
+ else:
121
+ fatal_error(f"Unknown command: {args.command}")
122
+ return 1
123
+
124
+
125
+ if __name__ == "__main__":
126
+ sys.exit(main())