llmcompressor 0.4.0__tar.gz

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 (165) hide show
  1. llmcompressor-0.4.0/LICENSE +201 -0
  2. llmcompressor-0.4.0/MANIFEST.in +1 -0
  3. llmcompressor-0.4.0/PKG-INFO +132 -0
  4. llmcompressor-0.4.0/README.md +104 -0
  5. llmcompressor-0.4.0/pyproject.toml +34 -0
  6. llmcompressor-0.4.0/setup.cfg +4 -0
  7. llmcompressor-0.4.0/setup.py +116 -0
  8. llmcompressor-0.4.0/src/llmcompressor/__init__.py +46 -0
  9. llmcompressor-0.4.0/src/llmcompressor/core/__init__.py +46 -0
  10. llmcompressor-0.4.0/src/llmcompressor/core/events/__init__.py +21 -0
  11. llmcompressor-0.4.0/src/llmcompressor/core/events/event.py +273 -0
  12. llmcompressor-0.4.0/src/llmcompressor/core/events/event_lifecycle.py +171 -0
  13. llmcompressor-0.4.0/src/llmcompressor/core/events/lifecycle_callbacks.py +191 -0
  14. llmcompressor-0.4.0/src/llmcompressor/core/events/lifecycle_optimizer.py +266 -0
  15. llmcompressor-0.4.0/src/llmcompressor/core/helpers.py +93 -0
  16. llmcompressor-0.4.0/src/llmcompressor/core/lifecycle.py +325 -0
  17. llmcompressor-0.4.0/src/llmcompressor/core/model_layer.py +21 -0
  18. llmcompressor-0.4.0/src/llmcompressor/core/session.py +331 -0
  19. llmcompressor-0.4.0/src/llmcompressor/core/session_functions.py +284 -0
  20. llmcompressor-0.4.0/src/llmcompressor/core/state.py +292 -0
  21. llmcompressor-0.4.0/src/llmcompressor/logger.py +132 -0
  22. llmcompressor-0.4.0/src/llmcompressor/metrics/__init__.py +3 -0
  23. llmcompressor-0.4.0/src/llmcompressor/metrics/logger.py +1362 -0
  24. llmcompressor-0.4.0/src/llmcompressor/metrics/utils/__init__.py +3 -0
  25. llmcompressor-0.4.0/src/llmcompressor/metrics/utils/frequency_manager.py +313 -0
  26. llmcompressor-0.4.0/src/llmcompressor/modifiers/__init__.py +11 -0
  27. llmcompressor-0.4.0/src/llmcompressor/modifiers/distillation/__init__.py +3 -0
  28. llmcompressor-0.4.0/src/llmcompressor/modifiers/distillation/output/__init__.py +3 -0
  29. llmcompressor-0.4.0/src/llmcompressor/modifiers/distillation/output/base.py +196 -0
  30. llmcompressor-0.4.0/src/llmcompressor/modifiers/distillation/utils/__init__.py +0 -0
  31. llmcompressor-0.4.0/src/llmcompressor/modifiers/distillation/utils/pytorch/__init__.py +5 -0
  32. llmcompressor-0.4.0/src/llmcompressor/modifiers/distillation/utils/pytorch/kd_factory.py +408 -0
  33. llmcompressor-0.4.0/src/llmcompressor/modifiers/distillation/utils/pytorch/kd_wrapper.py +116 -0
  34. llmcompressor-0.4.0/src/llmcompressor/modifiers/distillation/utils/pytorch/model_wrapper.py +135 -0
  35. llmcompressor-0.4.0/src/llmcompressor/modifiers/experimental/__init__.py +0 -0
  36. llmcompressor-0.4.0/src/llmcompressor/modifiers/factory.py +142 -0
  37. llmcompressor-0.4.0/src/llmcompressor/modifiers/interface.py +103 -0
  38. llmcompressor-0.4.0/src/llmcompressor/modifiers/logarithmic_equalization/__init__.py +3 -0
  39. llmcompressor-0.4.0/src/llmcompressor/modifiers/logarithmic_equalization/base.py +69 -0
  40. llmcompressor-0.4.0/src/llmcompressor/modifiers/modifier.py +304 -0
  41. llmcompressor-0.4.0/src/llmcompressor/modifiers/obcq/__init__.py +3 -0
  42. llmcompressor-0.4.0/src/llmcompressor/modifiers/obcq/base.py +333 -0
  43. llmcompressor-0.4.0/src/llmcompressor/modifiers/obcq/utils/__init__.py +0 -0
  44. llmcompressor-0.4.0/src/llmcompressor/modifiers/obcq/utils/sgpt_wrapper.py +226 -0
  45. llmcompressor-0.4.0/src/llmcompressor/modifiers/pruning/__init__.py +5 -0
  46. llmcompressor-0.4.0/src/llmcompressor/modifiers/pruning/constant/__init__.py +3 -0
  47. llmcompressor-0.4.0/src/llmcompressor/modifiers/pruning/constant/base.py +76 -0
  48. llmcompressor-0.4.0/src/llmcompressor/modifiers/pruning/helpers.py +170 -0
  49. llmcompressor-0.4.0/src/llmcompressor/modifiers/pruning/magnitude/__init__.py +3 -0
  50. llmcompressor-0.4.0/src/llmcompressor/modifiers/pruning/magnitude/base.py +135 -0
  51. llmcompressor-0.4.0/src/llmcompressor/modifiers/pruning/utils/__init__.py +0 -0
  52. llmcompressor-0.4.0/src/llmcompressor/modifiers/pruning/utils/pytorch/__init__.py +4 -0
  53. llmcompressor-0.4.0/src/llmcompressor/modifiers/pruning/utils/pytorch/layer_mask.py +153 -0
  54. llmcompressor-0.4.0/src/llmcompressor/modifiers/pruning/utils/pytorch/mask_factory.py +152 -0
  55. llmcompressor-0.4.0/src/llmcompressor/modifiers/pruning/wanda/__init__.py +3 -0
  56. llmcompressor-0.4.0/src/llmcompressor/modifiers/pruning/wanda/base.py +301 -0
  57. llmcompressor-0.4.0/src/llmcompressor/modifiers/pruning/wanda/utils/__init__.py +0 -0
  58. llmcompressor-0.4.0/src/llmcompressor/modifiers/pruning/wanda/utils/wanda_wrapper.py +125 -0
  59. llmcompressor-0.4.0/src/llmcompressor/modifiers/quantization/__init__.py +5 -0
  60. llmcompressor-0.4.0/src/llmcompressor/modifiers/quantization/cache.py +187 -0
  61. llmcompressor-0.4.0/src/llmcompressor/modifiers/quantization/calibration.py +249 -0
  62. llmcompressor-0.4.0/src/llmcompressor/modifiers/quantization/gptq/__init__.py +3 -0
  63. llmcompressor-0.4.0/src/llmcompressor/modifiers/quantization/gptq/base.py +408 -0
  64. llmcompressor-0.4.0/src/llmcompressor/modifiers/quantization/gptq/utils/__init__.py +3 -0
  65. llmcompressor-0.4.0/src/llmcompressor/modifiers/quantization/gptq/utils/gptq_quantize.py +290 -0
  66. llmcompressor-0.4.0/src/llmcompressor/modifiers/quantization/quantization/__init__.py +3 -0
  67. llmcompressor-0.4.0/src/llmcompressor/modifiers/quantization/quantization/base.py +380 -0
  68. llmcompressor-0.4.0/src/llmcompressor/modifiers/smoothquant/__init__.py +3 -0
  69. llmcompressor-0.4.0/src/llmcompressor/modifiers/smoothquant/base.py +353 -0
  70. llmcompressor-0.4.0/src/llmcompressor/modifiers/smoothquant/utils.py +92 -0
  71. llmcompressor-0.4.0/src/llmcompressor/modifiers/stage.py +164 -0
  72. llmcompressor-0.4.0/src/llmcompressor/modifiers/utils/__init__.py +3 -0
  73. llmcompressor-0.4.0/src/llmcompressor/modifiers/utils/compression_wrapper.py +117 -0
  74. llmcompressor-0.4.0/src/llmcompressor/modifiers/utils/constants.py +3 -0
  75. llmcompressor-0.4.0/src/llmcompressor/modifiers/utils/hooks.py +83 -0
  76. llmcompressor-0.4.0/src/llmcompressor/modifiers/utils/layer_compressor.py +181 -0
  77. llmcompressor-0.4.0/src/llmcompressor/modifiers/utils/pytorch_helpers.py +134 -0
  78. llmcompressor-0.4.0/src/llmcompressor/observers/__init__.py +7 -0
  79. llmcompressor-0.4.0/src/llmcompressor/observers/base.py +193 -0
  80. llmcompressor-0.4.0/src/llmcompressor/observers/helpers.py +22 -0
  81. llmcompressor-0.4.0/src/llmcompressor/observers/min_max.py +90 -0
  82. llmcompressor-0.4.0/src/llmcompressor/observers/mse.py +150 -0
  83. llmcompressor-0.4.0/src/llmcompressor/pipelines/__init__.py +0 -0
  84. llmcompressor-0.4.0/src/llmcompressor/pipelines/basic/__init__.py +2 -0
  85. llmcompressor-0.4.0/src/llmcompressor/pipelines/basic/pipeline.py +45 -0
  86. llmcompressor-0.4.0/src/llmcompressor/pipelines/cache.py +187 -0
  87. llmcompressor-0.4.0/src/llmcompressor/pipelines/layer_sequential/__init__.py +2 -0
  88. llmcompressor-0.4.0/src/llmcompressor/pipelines/layer_sequential/helpers.py +129 -0
  89. llmcompressor-0.4.0/src/llmcompressor/pipelines/layer_sequential/pipeline.py +84 -0
  90. llmcompressor-0.4.0/src/llmcompressor/pipelines/sequential/__init__.py +2 -0
  91. llmcompressor-0.4.0/src/llmcompressor/pipelines/sequential/helpers.py +365 -0
  92. llmcompressor-0.4.0/src/llmcompressor/pipelines/sequential/pipeline.py +85 -0
  93. llmcompressor-0.4.0/src/llmcompressor/pytorch/__init__.py +45 -0
  94. llmcompressor-0.4.0/src/llmcompressor/pytorch/model_load/__init__.py +0 -0
  95. llmcompressor-0.4.0/src/llmcompressor/pytorch/model_load/helpers.py +245 -0
  96. llmcompressor-0.4.0/src/llmcompressor/pytorch/utils/__init__.py +8 -0
  97. llmcompressor-0.4.0/src/llmcompressor/pytorch/utils/helpers.py +1196 -0
  98. llmcompressor-0.4.0/src/llmcompressor/pytorch/utils/sparsification.py +210 -0
  99. llmcompressor-0.4.0/src/llmcompressor/pytorch/utils/sparsification_info/__init__.py +0 -0
  100. llmcompressor-0.4.0/src/llmcompressor/pytorch/utils/sparsification_info/configs.py +380 -0
  101. llmcompressor-0.4.0/src/llmcompressor/pytorch/utils/sparsification_info/helpers.py +109 -0
  102. llmcompressor-0.4.0/src/llmcompressor/pytorch/utils/sparsification_info/module_sparsification_info.py +59 -0
  103. llmcompressor-0.4.0/src/llmcompressor/recipe/__init__.py +29 -0
  104. llmcompressor-0.4.0/src/llmcompressor/recipe/args.py +192 -0
  105. llmcompressor-0.4.0/src/llmcompressor/recipe/base.py +39 -0
  106. llmcompressor-0.4.0/src/llmcompressor/recipe/container.py +140 -0
  107. llmcompressor-0.4.0/src/llmcompressor/recipe/metadata.py +70 -0
  108. llmcompressor-0.4.0/src/llmcompressor/recipe/modifier.py +98 -0
  109. llmcompressor-0.4.0/src/llmcompressor/recipe/recipe.py +730 -0
  110. llmcompressor-0.4.0/src/llmcompressor/recipe/stage.py +203 -0
  111. llmcompressor-0.4.0/src/llmcompressor/transformers/__init__.py +14 -0
  112. llmcompressor-0.4.0/src/llmcompressor/transformers/compression/__init__.py +0 -0
  113. llmcompressor-0.4.0/src/llmcompressor/transformers/compression/helpers.py +372 -0
  114. llmcompressor-0.4.0/src/llmcompressor/transformers/compression/quantization_format.py +95 -0
  115. llmcompressor-0.4.0/src/llmcompressor/transformers/compression/sparsity_config.py +137 -0
  116. llmcompressor-0.4.0/src/llmcompressor/transformers/finetune/__init__.py +7 -0
  117. llmcompressor-0.4.0/src/llmcompressor/transformers/finetune/callbacks.py +112 -0
  118. llmcompressor-0.4.0/src/llmcompressor/transformers/finetune/data/__init__.py +14 -0
  119. llmcompressor-0.4.0/src/llmcompressor/transformers/finetune/data/base.py +328 -0
  120. llmcompressor-0.4.0/src/llmcompressor/transformers/finetune/data/c4.py +26 -0
  121. llmcompressor-0.4.0/src/llmcompressor/transformers/finetune/data/cnn_dailymail.py +35 -0
  122. llmcompressor-0.4.0/src/llmcompressor/transformers/finetune/data/custom.py +17 -0
  123. llmcompressor-0.4.0/src/llmcompressor/transformers/finetune/data/data_args.py +189 -0
  124. llmcompressor-0.4.0/src/llmcompressor/transformers/finetune/data/data_helpers.py +245 -0
  125. llmcompressor-0.4.0/src/llmcompressor/transformers/finetune/data/evolcodealpaca.py +44 -0
  126. llmcompressor-0.4.0/src/llmcompressor/transformers/finetune/data/flickr_30k.py +68 -0
  127. llmcompressor-0.4.0/src/llmcompressor/transformers/finetune/data/gsm8k.py +39 -0
  128. llmcompressor-0.4.0/src/llmcompressor/transformers/finetune/data/open_platypus.py +54 -0
  129. llmcompressor-0.4.0/src/llmcompressor/transformers/finetune/data/ptb.py +30 -0
  130. llmcompressor-0.4.0/src/llmcompressor/transformers/finetune/data/ultrachat_200k.py +67 -0
  131. llmcompressor-0.4.0/src/llmcompressor/transformers/finetune/data/wikitext.py +30 -0
  132. llmcompressor-0.4.0/src/llmcompressor/transformers/finetune/model_args.py +85 -0
  133. llmcompressor-0.4.0/src/llmcompressor/transformers/finetune/runner.py +285 -0
  134. llmcompressor-0.4.0/src/llmcompressor/transformers/finetune/session_mixin.py +634 -0
  135. llmcompressor-0.4.0/src/llmcompressor/transformers/finetune/text_generation.py +440 -0
  136. llmcompressor-0.4.0/src/llmcompressor/transformers/finetune/trainer.py +9 -0
  137. llmcompressor-0.4.0/src/llmcompressor/transformers/finetune/training_args.py +71 -0
  138. llmcompressor-0.4.0/src/llmcompressor/transformers/sparsification/__init__.py +7 -0
  139. llmcompressor-0.4.0/src/llmcompressor/transformers/sparsification/compressed_tensors_utils.py +311 -0
  140. llmcompressor-0.4.0/src/llmcompressor/transformers/sparsification/sparse_model.py +49 -0
  141. llmcompressor-0.4.0/src/llmcompressor/transformers/tracing/__init__.py +13 -0
  142. llmcompressor-0.4.0/src/llmcompressor/transformers/tracing/llava.py +274 -0
  143. llmcompressor-0.4.0/src/llmcompressor/transformers/tracing/mistral.py +251 -0
  144. llmcompressor-0.4.0/src/llmcompressor/transformers/tracing/mllama.py +161 -0
  145. llmcompressor-0.4.0/src/llmcompressor/transformers/utils/__init__.py +6 -0
  146. llmcompressor-0.4.0/src/llmcompressor/transformers/utils/data_collator.py +48 -0
  147. llmcompressor-0.4.0/src/llmcompressor/transformers/utils/helpers.py +56 -0
  148. llmcompressor-0.4.0/src/llmcompressor/transformers/utils/preprocessing_functions.py +18 -0
  149. llmcompressor-0.4.0/src/llmcompressor/typing.py +17 -0
  150. llmcompressor-0.4.0/src/llmcompressor/utils/__init__.py +7 -0
  151. llmcompressor-0.4.0/src/llmcompressor/utils/fsdp/__init__.py +1 -0
  152. llmcompressor-0.4.0/src/llmcompressor/utils/fsdp/context.py +57 -0
  153. llmcompressor-0.4.0/src/llmcompressor/utils/fsdp/helpers.py +182 -0
  154. llmcompressor-0.4.0/src/llmcompressor/utils/helpers.py +1115 -0
  155. llmcompressor-0.4.0/src/llmcompressor/utils/metric_logging.py +145 -0
  156. llmcompressor-0.4.0/src/llmcompressor/utils/pytorch/__init__.py +3 -0
  157. llmcompressor-0.4.0/src/llmcompressor/utils/pytorch/module.py +340 -0
  158. llmcompressor-0.4.0/src/llmcompressor/utils/pytorch/utils.py +36 -0
  159. llmcompressor-0.4.0/src/llmcompressor/version.py +54 -0
  160. llmcompressor-0.4.0/src/llmcompressor.egg-info/PKG-INFO +132 -0
  161. llmcompressor-0.4.0/src/llmcompressor.egg-info/SOURCES.txt +163 -0
  162. llmcompressor-0.4.0/src/llmcompressor.egg-info/dependency_links.txt +1 -0
  163. llmcompressor-0.4.0/src/llmcompressor.egg-info/entry_points.txt +7 -0
  164. llmcompressor-0.4.0/src/llmcompressor.egg-info/requires.txt +28 -0
  165. llmcompressor-0.4.0/src/llmcompressor.egg-info/top_level.txt +1 -0
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1 @@
1
+ include LICENSE
@@ -0,0 +1,132 @@
1
+ Metadata-Version: 2.1
2
+ Name: llmcompressor
3
+ Version: 0.4.0
4
+ Summary: A library for compressing large language models utilizing the latest techniques and research in the field for both training aware and post training techniques. The library is designed to be flexible and easy to use on top of PyTorch and HuggingFace Transformers, allowing for quick experimentation.
5
+ Home-page: https://github.com/neuralmagic/llm-compressor
6
+ Author: Neuralmagic, Inc.
7
+ Author-email: support@neuralmagic.com
8
+ License: Apache
9
+ Keywords: llmcompressor,llms,large language models,transformers,pytorch,huggingface,compressors,compression,quantization,pruning,sparsity,optimization,model optimization,model compression,
10
+ Classifier: Development Status :: 5 - Production/Stable
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Programming Language :: Python :: 3 :: Only
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Intended Audience :: Education
15
+ Classifier: Intended Audience :: Information Technology
16
+ Classifier: Intended Audience :: Science/Research
17
+ Classifier: License :: OSI Approved :: Apache Software License
18
+ Classifier: Operating System :: POSIX :: Linux
19
+ Classifier: Topic :: Scientific/Engineering
20
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
21
+ Classifier: Topic :: Scientific/Engineering :: Mathematics
22
+ Classifier: Topic :: Software Development
23
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
24
+ Requires-Python: >=3.8
25
+ Description-Content-Type: text/markdown
26
+ Provides-Extra: dev
27
+ License-File: LICENSE
28
+
29
+ # <img width="40" alt="tool icon" src="https://github.com/user-attachments/assets/f9b86465-aefa-4625-a09b-54e158efcf96" /> LLM Compressor
30
+ `llmcompressor` is an easy-to-use library for optimizing models for deployment with `vllm`, including:
31
+
32
+ * Comprehensive set of quantization algorithms for weight-only and activation quantization
33
+ * Seamless integration with Hugging Face models and repositories
34
+ * `safetensors`-based file format compatible with `vllm`
35
+ * Large model support via `accelerate`
36
+
37
+ **✨ Read the announcement blog [here](https://neuralmagic.com/blog/llm-compressor-is-here-faster-inference-with-vllm/)! ✨**
38
+
39
+ <p align="center">
40
+ <img alt="LLM Compressor Flow" src="https://github.com/user-attachments/assets/adf07594-6487-48ae-af62-d9555046d51b" width="80%" />
41
+ </p>
42
+
43
+ ### Supported Formats
44
+ * Activation Quantization: W8A8 (int8 and fp8)
45
+ * Mixed Precision: W4A16, W8A16
46
+ * 2:4 Semi-structured and Unstructured Sparsity
47
+
48
+ ### Supported Algorithms
49
+ * Simple PTQ
50
+ * GPTQ
51
+ * SmoothQuant
52
+ * SparseGPT
53
+
54
+
55
+ ## Installation
56
+
57
+ ```bash
58
+ pip install llmcompressor
59
+ ```
60
+
61
+ ## Get Started
62
+
63
+ ### End-to-End Examples
64
+
65
+ Applying quantization with `llmcompressor`:
66
+ * [Activation quantization to `int8`](examples/quantization_w8a8_int8)
67
+ * [Activation quantization to `fp8`](examples/quantization_w8a8_fp8)
68
+ * [Weight only quantization to `int4`](examples/quantization_w4a16)
69
+ * [Quantizing MoE LLMs](examples/quantizing_moe)
70
+
71
+ ### User Guides
72
+ Deep dives into advanced usage of `llmcompressor`:
73
+ * [Quantizing with large models with the help of `accelerate`](examples/big_models_with_accelerate)
74
+
75
+
76
+ ## Quick Tour
77
+ Let's quantize `TinyLlama` with 8 bit weights and activations using the `GPTQ` and `SmoothQuant` algorithms.
78
+
79
+ Note that the model can be swapped for a local or remote HF-compatible checkpoint and the `recipe` may be changed to target different quantization algorithms or formats.
80
+
81
+ ### Apply Quantization
82
+ Quantization is applied by selecting an algorithm and calling the `oneshot` API.
83
+
84
+ ```python
85
+ from llmcompressor.modifiers.quantization import GPTQModifier
86
+ from llmcompressor.modifiers.smoothquant import SmoothQuantModifier
87
+ from llmcompressor.transformers import oneshot
88
+ from transformers import AutoModelForCausalLM
89
+
90
+ # Select quantization algorithm. In this case, we:
91
+ # * apply SmoothQuant to make the activations easier to quantize
92
+ # * quantize the weights to int8 with GPTQ (static per channel)
93
+ # * quantize the activations to int8 (dynamic per token)
94
+ recipe = [
95
+ SmoothQuantModifier(smoothing_strength=0.8),
96
+ GPTQModifier(scheme="W8A8", targets="Linear", ignore=["lm_head"]),
97
+ ]
98
+
99
+ # Apply quantization using the built in open_platypus dataset.
100
+ # * See examples for demos showing how to pass a custom calibration set
101
+ oneshot(
102
+ model="TinyLlama/TinyLlama-1.1B-Chat-v1.0",
103
+ dataset="open_platypus",
104
+ recipe=recipe,
105
+ output_dir="TinyLlama-1.1B-Chat-v1.0-INT8",
106
+ max_seq_length=2048,
107
+ num_calibration_samples=512,
108
+ )
109
+ ```
110
+
111
+ ### Inference with vLLM
112
+
113
+ The checkpoints created by `llmcompressor` can be loaded and run in `vllm`:
114
+
115
+ Install:
116
+
117
+ ```bash
118
+ pip install vllm
119
+ ```
120
+
121
+ Run:
122
+
123
+ ```python
124
+ from vllm import LLM
125
+ model = LLM("TinyLlama-1.1B-Chat-v1.0-INT8")
126
+ output = model.generate("My name is")
127
+ ```
128
+
129
+ ## Questions / Contribution
130
+
131
+ - If you have any questions or requests open an [issue](https://github.com/vllm-project/llm-compressor/issues) and we will add an example or documentation.
132
+ - We appreciate contributions to the code, examples, integrations, and documentation as well as bug reports and feature requests! [Learn how here](CONTRIBUTING.md).
@@ -0,0 +1,104 @@
1
+ # <img width="40" alt="tool icon" src="https://github.com/user-attachments/assets/f9b86465-aefa-4625-a09b-54e158efcf96" /> LLM Compressor
2
+ `llmcompressor` is an easy-to-use library for optimizing models for deployment with `vllm`, including:
3
+
4
+ * Comprehensive set of quantization algorithms for weight-only and activation quantization
5
+ * Seamless integration with Hugging Face models and repositories
6
+ * `safetensors`-based file format compatible with `vllm`
7
+ * Large model support via `accelerate`
8
+
9
+ **✨ Read the announcement blog [here](https://neuralmagic.com/blog/llm-compressor-is-here-faster-inference-with-vllm/)! ✨**
10
+
11
+ <p align="center">
12
+ <img alt="LLM Compressor Flow" src="https://github.com/user-attachments/assets/adf07594-6487-48ae-af62-d9555046d51b" width="80%" />
13
+ </p>
14
+
15
+ ### Supported Formats
16
+ * Activation Quantization: W8A8 (int8 and fp8)
17
+ * Mixed Precision: W4A16, W8A16
18
+ * 2:4 Semi-structured and Unstructured Sparsity
19
+
20
+ ### Supported Algorithms
21
+ * Simple PTQ
22
+ * GPTQ
23
+ * SmoothQuant
24
+ * SparseGPT
25
+
26
+
27
+ ## Installation
28
+
29
+ ```bash
30
+ pip install llmcompressor
31
+ ```
32
+
33
+ ## Get Started
34
+
35
+ ### End-to-End Examples
36
+
37
+ Applying quantization with `llmcompressor`:
38
+ * [Activation quantization to `int8`](examples/quantization_w8a8_int8)
39
+ * [Activation quantization to `fp8`](examples/quantization_w8a8_fp8)
40
+ * [Weight only quantization to `int4`](examples/quantization_w4a16)
41
+ * [Quantizing MoE LLMs](examples/quantizing_moe)
42
+
43
+ ### User Guides
44
+ Deep dives into advanced usage of `llmcompressor`:
45
+ * [Quantizing with large models with the help of `accelerate`](examples/big_models_with_accelerate)
46
+
47
+
48
+ ## Quick Tour
49
+ Let's quantize `TinyLlama` with 8 bit weights and activations using the `GPTQ` and `SmoothQuant` algorithms.
50
+
51
+ Note that the model can be swapped for a local or remote HF-compatible checkpoint and the `recipe` may be changed to target different quantization algorithms or formats.
52
+
53
+ ### Apply Quantization
54
+ Quantization is applied by selecting an algorithm and calling the `oneshot` API.
55
+
56
+ ```python
57
+ from llmcompressor.modifiers.quantization import GPTQModifier
58
+ from llmcompressor.modifiers.smoothquant import SmoothQuantModifier
59
+ from llmcompressor.transformers import oneshot
60
+ from transformers import AutoModelForCausalLM
61
+
62
+ # Select quantization algorithm. In this case, we:
63
+ # * apply SmoothQuant to make the activations easier to quantize
64
+ # * quantize the weights to int8 with GPTQ (static per channel)
65
+ # * quantize the activations to int8 (dynamic per token)
66
+ recipe = [
67
+ SmoothQuantModifier(smoothing_strength=0.8),
68
+ GPTQModifier(scheme="W8A8", targets="Linear", ignore=["lm_head"]),
69
+ ]
70
+
71
+ # Apply quantization using the built in open_platypus dataset.
72
+ # * See examples for demos showing how to pass a custom calibration set
73
+ oneshot(
74
+ model="TinyLlama/TinyLlama-1.1B-Chat-v1.0",
75
+ dataset="open_platypus",
76
+ recipe=recipe,
77
+ output_dir="TinyLlama-1.1B-Chat-v1.0-INT8",
78
+ max_seq_length=2048,
79
+ num_calibration_samples=512,
80
+ )
81
+ ```
82
+
83
+ ### Inference with vLLM
84
+
85
+ The checkpoints created by `llmcompressor` can be loaded and run in `vllm`:
86
+
87
+ Install:
88
+
89
+ ```bash
90
+ pip install vllm
91
+ ```
92
+
93
+ Run:
94
+
95
+ ```python
96
+ from vllm import LLM
97
+ model = LLM("TinyLlama-1.1B-Chat-v1.0-INT8")
98
+ output = model.generate("My name is")
99
+ ```
100
+
101
+ ## Questions / Contribution
102
+
103
+ - If you have any questions or requests open an [issue](https://github.com/vllm-project/llm-compressor/issues) and we will add an example or documentation.
104
+ - We appreciate contributions to the code, examples, integrations, and documentation as well as bug reports and feature requests! [Learn how here](CONTRIBUTING.md).
@@ -0,0 +1,34 @@
1
+ [build-system]
2
+ requires = ["setuptools", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [tool.black]
6
+ line-length = 88
7
+ target-version = ['py38']
8
+
9
+ [tool.isort]
10
+ profile = "black"
11
+ skip = ["src/llmcompressor/transformers/tracing/"]
12
+
13
+ [tool.mypy]
14
+ files = "src/guidellm"
15
+
16
+ [tool.ruff]
17
+ exclude = ["build", "dist", "env", ".venv", "src/llmcompressor/transformers/tracing/"]
18
+ lint.select = ["E", "F", "W"]
19
+
20
+ [tool.flake8]
21
+ max-line-length = 88
22
+ extend-ignore = 'E203'
23
+
24
+ [tool.pytest.ini_options]
25
+ markers = [
26
+ "smoke: quick tests to check basic functionality",
27
+ "sanity: tests to ensure that new changes do not break existing functionality",
28
+ "regression: detailed tests to ensure major functions work correctly",
29
+ "integration: tests which integrate with a third party service such as HF",
30
+ "unit: tests to ensure code correctness and regression test functionality",
31
+ "example: tests for content in the 'examples' folder",
32
+ "multi_gpu: tests that require multiple GPUs",
33
+ ]
34
+ tmp_path_retention_policy = "failed"
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,116 @@
1
+ import os
2
+ import sys
3
+
4
+ from setuptools import find_packages, setup
5
+
6
+ sys.path.insert(0, os.path.abspath(os.path.dirname(__file__)))
7
+ from utils.version_extractor import extract_version_info # noqa isort:skip
8
+
9
+ # load version info for the package
10
+ package_path = os.path.join(
11
+ os.path.dirname(os.path.realpath(__file__)), "src", "llmcompressor"
12
+ )
13
+ version_info = extract_version_info(package_path)
14
+
15
+ if version_info.build_type == "release":
16
+ package_name = "llmcompressor"
17
+ elif version_info.build_type == "dev":
18
+ package_name = "llmcompressor-dev"
19
+ elif version_info.build_type == "nightly":
20
+ package_name = "llmcompressor-nightly"
21
+ else:
22
+ raise ValueError(f"Unsupported build type {version_info.build_type}")
23
+
24
+
25
+ setup(
26
+ name=package_name,
27
+ version=version_info.version,
28
+ author="Neuralmagic, Inc.",
29
+ author_email="support@neuralmagic.com",
30
+ description=(
31
+ "A library for compressing large language models utilizing the "
32
+ "latest techniques and research in the field for both "
33
+ "training aware and post training techniques. "
34
+ "The library is designed to be flexible and easy to use on top of "
35
+ "PyTorch and HuggingFace Transformers, allowing for quick experimentation."
36
+ ),
37
+ long_description=open("README.md", "r", encoding="utf-8").read(),
38
+ long_description_content_type="text/markdown",
39
+ keywords=(
40
+ "llmcompressor, llms, large language models, transformers, pytorch, "
41
+ "huggingface, compressors, compression, quantization, pruning, "
42
+ "sparsity, optimization, model optimization, model compression, "
43
+ ),
44
+ license="Apache",
45
+ url="https://github.com/neuralmagic/llm-compressor",
46
+ include_package_data=True,
47
+ package_dir={"": "src"},
48
+ packages=find_packages(
49
+ "src", include=["llmcompressor", "llmcompressor.*"], exclude=["*.__pycache__.*"]
50
+ ),
51
+ install_requires=[
52
+ "loguru",
53
+ "pyyaml>=5.0.0",
54
+ "numpy>=1.17.0,<2.0",
55
+ "requests>=2.0.0",
56
+ "tqdm>=4.0.0",
57
+ "click>=7.1.2,!=8.0.0", # 8.0.0 blocked due to reported bug
58
+ "torch>=1.7.0",
59
+ "transformers>4.0,<5.0",
60
+ "datasets",
61
+ "accelerate>=0.20.3,!=1.1.0",
62
+ "pynvml==11.5.3",
63
+ "compressed-tensors==0.9.0"
64
+ if version_info.build_type == "release"
65
+ else "compressed-tensors-nightly",
66
+ ],
67
+ extras_require={
68
+ "dev": [
69
+ # testing framework
70
+ "pytest>=6.0.0",
71
+ "pytest-mock>=3.6.0",
72
+ "pytest-rerunfailures>=13.0",
73
+ "parameterized",
74
+ "lm_eval==0.4.5",
75
+ # example test dependencies
76
+ "beautifulsoup4~=4.12.3",
77
+ "cmarkgfm~=2024.1.14",
78
+ "trl>=0.10.1",
79
+ # linting, formatting, and type checking
80
+ "black~=24.4.2",
81
+ "isort~=5.13.2",
82
+ "mypy~=1.10.0",
83
+ "ruff~=0.4.8",
84
+ "flake8~=7.0.0",
85
+ # pre commit hooks
86
+ "pre-commit",
87
+ ]
88
+ },
89
+ entry_points={
90
+ "console_scripts": [
91
+ "llmcompressor.transformers.text_generation.apply=llmcompressor.transformers.finetune.text_generation:apply", # noqa 501
92
+ "llmcompressor.transformers.text_generation.compress=llmcompressor.transformers.finetune.text_generation:apply", # noqa 501
93
+ "llmcompressor.transformers.text_generation.train=llmcompressor.transformers.finetune.text_generation:train", # noqa 501
94
+ "llmcompressor.transformers.text_generation.finetune=llmcompressor.transformers.finetune.text_generation:train", # noqa 501
95
+ "llmcompressor.transformers.text_generation.eval=llmcompressor.transformers.finetune.text_generation:eval", # noqa 501
96
+ "llmcompressor.transformers.text_generation.oneshot=llmcompressor.transformers.finetune.text_generation:oneshot", # noqa 501
97
+ ]
98
+ },
99
+ python_requires=">=3.8",
100
+ classifiers=[
101
+ "Development Status :: 5 - Production/Stable",
102
+ "Programming Language :: Python :: 3",
103
+ "Programming Language :: Python :: 3 :: Only",
104
+ "Intended Audience :: Developers",
105
+ "Intended Audience :: Education",
106
+ "Intended Audience :: Information Technology",
107
+ "Intended Audience :: Science/Research",
108
+ "License :: OSI Approved :: Apache Software License",
109
+ "Operating System :: POSIX :: Linux",
110
+ "Topic :: Scientific/Engineering",
111
+ "Topic :: Scientific/Engineering :: Artificial Intelligence",
112
+ "Topic :: Scientific/Engineering :: Mathematics",
113
+ "Topic :: Software Development",
114
+ "Topic :: Software Development :: Libraries :: Python Modules",
115
+ ],
116
+ )
@@ -0,0 +1,46 @@
1
+ """
2
+ A library for compressing large language models utilizing the latest techniques and
3
+ research in the field for both training aware and post training techniques.
4
+
5
+ The library is designed to be flexible and easy to use on top of
6
+ PyTorch and HuggingFace Transformers, allowing for quick experimentation.
7
+ """
8
+
9
+ # flake8: noqa
10
+
11
+ from .logger import LoggerConfig, configure_logger, logger
12
+ from .version import (
13
+ __version__,
14
+ build_type,
15
+ version,
16
+ version_base,
17
+ version_build,
18
+ version_major,
19
+ version_minor,
20
+ version_patch,
21
+ )
22
+
23
+ __all__ = [
24
+ "__version__",
25
+ "version_base",
26
+ "build_type",
27
+ "version",
28
+ "version_major",
29
+ "version_minor",
30
+ "version_patch",
31
+ "version_build",
32
+ "configure_logger",
33
+ "logger",
34
+ "LoggerConfig",
35
+ ]
36
+
37
+ from llmcompressor.core.session_functions import (
38
+ active_session,
39
+ apply,
40
+ callbacks,
41
+ create_session,
42
+ finalize,
43
+ initialize,
44
+ pre_initialize_structure,
45
+ reset_session,
46
+ )