Instructions to use ya9919/sharp-9b with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- PEFT
How to use ya9919/sharp-9b with PEFT:
Task type is invalid.
- Notebooks
- Google Colab
- Kaggle
Commit ·
6888745
0
Parent(s):
S²-MAS research release
Browse files- .gitattributes +35 -0
- LICENSE +223 -0
- README.md +76 -0
- adapter/adapter_config.json +55 -0
- adapter/adapter_model.safetensors +3 -0
- decision_config.json +12 -0
- head.pt +3 -0
- qwen_decision.py +250 -0
- release_metadata.json +25 -0
.gitattributes
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
| 2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
| 3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
| 4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
| 5 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
| 6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
| 7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
| 8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
| 9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
| 10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
| 11 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
| 12 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
| 13 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
| 14 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
| 15 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
| 16 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
| 17 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
| 18 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
| 19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
| 20 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
| 21 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
| 22 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
| 23 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
| 24 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
| 25 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
| 26 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
| 27 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
| 28 |
+
*.tar filter=lfs diff=lfs merge=lfs -text
|
| 29 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
| 30 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
| 31 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
| 32 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
| 33 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
+
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
LICENSE
ADDED
|
@@ -0,0 +1,223 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
S²-MAS Controlled Model Research License, version 1.2
|
| 2 |
+
19 October 2026
|
| 3 |
+
|
| 4 |
+
Copyright 2026 S²-MAS authors, to the extent of rights held in the project contributions.
|
| 5 |
+
|
| 6 |
+
1. Scope. This prospective distribution offer applies to the project-owned model contributions offered in this repository and its derivative model distribution. It changes no model parameters, training or evaluation. By accepting and exercising the permissions in this offer, the recipient agrees to the following conditions.
|
| 7 |
+
|
| 8 |
+
2. Noncommercial research. The recipient may copy, store, load and run the supplied model locally for noncommercial scientific research and evaluation, and publish attributed, non-identifying aggregate findings. Commercial use requires prior written permission. Commercial use includes paid products or services, commercial deployment, consulting, business operations or decisions, and developing models or products for commercial distribution. Commercial entities require separate written permission.
|
| 9 |
+
|
| 10 |
+
3. No redistribution. Without prior written permission, do not sell, rent, sublicense, share, mirror, rehost, publicly upload or distribute the covered material, substantial parameter extracts or model derivatives. Do not expose it to third parties through an API, endpoint, hosted demo or model service. Each recipient obtains permission from the authors.
|
| 11 |
+
|
| 12 |
+
4. No unauthorized reverse engineering. Without prior written permission, do not reverse engineer, decompile, disassemble, reconstruct, extract, imitate or distill the covered project model; perform model inversion or parameter-extraction attacks; recover its parameters or training records through probes or outputs; or circumvent access controls. Do not reconstruct confidential source records or identify individuals. Reading and loading the supplied weights as needed for permitted evaluation is allowed. Non-waivable statutory exceptions remain effective.
|
| 13 |
+
|
| 14 |
+
5. Other permissions. Training, fine-tuning, weight modification, model integration, distillation or derivative distribution requires separate written permission. Preserve this license and applicable upstream notices. Cite the model name and version when reporting research. No training records or source-data access is granted; obtain restricted inputs through their authorized providers. Wikidata structured facts retain CC0 independently.
|
| 15 |
+
|
| 16 |
+
6. Breach. Breach terminates permissions granted solely by this offer. Stop use and remove copies held only under it, except for mandatory retention. Independent rights continue. Other rights are reserved. The material is provided as is, without warranty, to the extent permitted by law. This is a restricted research-use offer, not an OSI open-source license.
|
| 17 |
+
|
| 18 |
+
Permission requests: yli9919@hku.hk.
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
APPENDIX — ORIGINAL APACHE-2.0 LICENSE
|
| 22 |
+
|
| 23 |
+
Apache License
|
| 24 |
+
Version 2.0, January 2004
|
| 25 |
+
http://www.apache.org/licenses/
|
| 26 |
+
|
| 27 |
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
| 28 |
+
|
| 29 |
+
1. Definitions.
|
| 30 |
+
|
| 31 |
+
"License" shall mean the terms and conditions for use, reproduction,
|
| 32 |
+
and distribution as defined by Sections 1 through 9 of this document.
|
| 33 |
+
|
| 34 |
+
"Licensor" shall mean the copyright owner or entity authorized by
|
| 35 |
+
the copyright owner that is granting the License.
|
| 36 |
+
|
| 37 |
+
"Legal Entity" shall mean the union of the acting entity and all
|
| 38 |
+
other entities that control, are controlled by, or are under common
|
| 39 |
+
control with that entity. For the purposes of this definition,
|
| 40 |
+
"control" means (i) the power, direct or indirect, to cause the
|
| 41 |
+
direction or management of such entity, whether by contract or
|
| 42 |
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
| 43 |
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
| 44 |
+
|
| 45 |
+
"You" (or "Your") shall mean an individual or Legal Entity
|
| 46 |
+
exercising permissions granted by this License.
|
| 47 |
+
|
| 48 |
+
"Source" form shall mean the preferred form for making modifications,
|
| 49 |
+
including but not limited to software source code, documentation
|
| 50 |
+
source, and configuration files.
|
| 51 |
+
|
| 52 |
+
"Object" form shall mean any form resulting from mechanical
|
| 53 |
+
transformation or translation of a Source form, including but
|
| 54 |
+
not limited to compiled object code, generated documentation,
|
| 55 |
+
and conversions to other media types.
|
| 56 |
+
|
| 57 |
+
"Work" shall mean the work of authorship, whether in Source or
|
| 58 |
+
Object form, made available under the License, as indicated by a
|
| 59 |
+
copyright notice that is included in or attached to the work
|
| 60 |
+
(an example is provided in the Appendix below).
|
| 61 |
+
|
| 62 |
+
"Derivative Works" shall mean any work, whether in Source or Object
|
| 63 |
+
form, that is based on (or derived from) the Work and for which the
|
| 64 |
+
editorial revisions, annotations, elaborations, or other modifications
|
| 65 |
+
represent, as a whole, an original work of authorship. For the purposes
|
| 66 |
+
of this License, Derivative Works shall not include works that remain
|
| 67 |
+
separable from, or merely link (or bind by name) to the interfaces of,
|
| 68 |
+
the Work and Derivative Works thereof.
|
| 69 |
+
|
| 70 |
+
"Contribution" shall mean any work of authorship, including
|
| 71 |
+
the original version of the Work and any modifications or additions
|
| 72 |
+
to that Work or Derivative Works thereof, that is intentionally
|
| 73 |
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
| 74 |
+
or by an individual or Legal Entity authorized to submit on behalf of
|
| 75 |
+
the copyright owner. For the purposes of this definition, "submitted"
|
| 76 |
+
means any form of electronic, verbal, or written communication sent
|
| 77 |
+
to the Licensor or its representatives, including but not limited to
|
| 78 |
+
communication on electronic mailing lists, source code control systems,
|
| 79 |
+
and issue tracking systems that are managed by, or on behalf of, the
|
| 80 |
+
Licensor for the purpose of discussing and improving the Work, but
|
| 81 |
+
excluding communication that is conspicuously marked or otherwise
|
| 82 |
+
designated in writing by the copyright owner as "Not a Contribution."
|
| 83 |
+
|
| 84 |
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
| 85 |
+
on behalf of whom a Contribution has been received by Licensor and
|
| 86 |
+
subsequently incorporated within the Work.
|
| 87 |
+
|
| 88 |
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
| 89 |
+
this License, each Contributor hereby grants to You a perpetual,
|
| 90 |
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
| 91 |
+
copyright license to reproduce, prepare Derivative Works of,
|
| 92 |
+
publicly display, publicly perform, sublicense, and distribute the
|
| 93 |
+
Work and such Derivative Works in Source or Object form.
|
| 94 |
+
|
| 95 |
+
3. Grant of Patent License. Subject to the terms and conditions of
|
| 96 |
+
this License, each Contributor hereby grants to You a perpetual,
|
| 97 |
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
| 98 |
+
(except as stated in this section) patent license to make, have made,
|
| 99 |
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
| 100 |
+
where such license applies only to those patent claims licensable
|
| 101 |
+
by such Contributor that are necessarily infringed by their
|
| 102 |
+
Contribution(s) alone or by combination of their Contribution(s)
|
| 103 |
+
with the Work to which such Contribution(s) was submitted. If You
|
| 104 |
+
institute patent litigation against any entity (including a
|
| 105 |
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
| 106 |
+
or a Contribution incorporated within the Work constitutes direct
|
| 107 |
+
or contributory patent infringement, then any patent licenses
|
| 108 |
+
granted to You under this License for that Work shall terminate
|
| 109 |
+
as of the date such litigation is filed.
|
| 110 |
+
|
| 111 |
+
4. Redistribution. You may reproduce and distribute copies of the
|
| 112 |
+
Work or Derivative Works thereof in any medium, with or without
|
| 113 |
+
modifications, and in Source or Object form, provided that You
|
| 114 |
+
meet the following conditions:
|
| 115 |
+
|
| 116 |
+
(a) You must give any other recipients of the Work or
|
| 117 |
+
Derivative Works a copy of this License; and
|
| 118 |
+
|
| 119 |
+
(b) You must cause any modified files to carry prominent notices
|
| 120 |
+
stating that You changed the files; and
|
| 121 |
+
|
| 122 |
+
(c) You must retain, in the Source form of any Derivative Works
|
| 123 |
+
that You distribute, all copyright, patent, trademark, and
|
| 124 |
+
attribution notices from the Source form of the Work,
|
| 125 |
+
excluding those notices that do not pertain to any part of
|
| 126 |
+
the Derivative Works; and
|
| 127 |
+
|
| 128 |
+
(d) If the Work includes a "NOTICE" text file as part of its
|
| 129 |
+
distribution, then any Derivative Works that You distribute must
|
| 130 |
+
include a readable copy of the attribution notices contained
|
| 131 |
+
within such NOTICE file, excluding those notices that do not
|
| 132 |
+
pertain to any part of the Derivative Works, in at least one
|
| 133 |
+
of the following places: within a NOTICE text file distributed
|
| 134 |
+
as part of the Derivative Works; within the Source form or
|
| 135 |
+
documentation, if provided along with the Derivative Works; or,
|
| 136 |
+
within a display generated by the Derivative Works, if and
|
| 137 |
+
wherever such third-party notices normally appear. The contents
|
| 138 |
+
of the NOTICE file are for informational purposes only and
|
| 139 |
+
do not modify the License. You may add Your own attribution
|
| 140 |
+
notices within Derivative Works that You distribute, alongside
|
| 141 |
+
or as an addendum to the NOTICE text from the Work, provided
|
| 142 |
+
that such additional attribution notices cannot be construed
|
| 143 |
+
as modifying the License.
|
| 144 |
+
|
| 145 |
+
You may add Your own copyright statement to Your modifications and
|
| 146 |
+
may provide additional or different license terms and conditions
|
| 147 |
+
for use, reproduction, or distribution of Your modifications, or
|
| 148 |
+
for any such Derivative Works as a whole, provided Your use,
|
| 149 |
+
reproduction, and distribution of the Work otherwise complies with
|
| 150 |
+
the conditions stated in this License.
|
| 151 |
+
|
| 152 |
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
| 153 |
+
any Contribution intentionally submitted for inclusion in the Work
|
| 154 |
+
by You to the Licensor shall be under the terms and conditions of
|
| 155 |
+
this License, without any additional terms or conditions.
|
| 156 |
+
Notwithstanding the above, nothing herein shall supersede or modify
|
| 157 |
+
the terms of any separate license agreement you may have executed
|
| 158 |
+
with Licensor regarding such Contributions.
|
| 159 |
+
|
| 160 |
+
6. Trademarks. This License does not grant permission to use the trade
|
| 161 |
+
names, trademarks, service marks, or product names of the Licensor,
|
| 162 |
+
except as required for reasonable and customary use in describing the
|
| 163 |
+
origin of the Work and reproducing the content of the NOTICE file.
|
| 164 |
+
|
| 165 |
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
| 166 |
+
agreed to in writing, Licensor provides the Work (and each
|
| 167 |
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
| 168 |
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
| 169 |
+
implied, including, without limitation, any warranties or conditions
|
| 170 |
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
| 171 |
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
| 172 |
+
appropriateness of using or redistributing the Work and assume any
|
| 173 |
+
risks associated with Your exercise of permissions under this License.
|
| 174 |
+
|
| 175 |
+
8. Limitation of Liability. In no event and under no legal theory,
|
| 176 |
+
whether in tort (including negligence), contract, or otherwise,
|
| 177 |
+
unless required by applicable law (such as deliberate and grossly
|
| 178 |
+
negligent acts) or agreed to in writing, shall any Contributor be
|
| 179 |
+
liable to You for damages, including any direct, indirect, special,
|
| 180 |
+
incidental, or consequential damages of any character arising as a
|
| 181 |
+
result of this License or out of the use or inability to use the
|
| 182 |
+
Work (including but not limited to damages for loss of goodwill,
|
| 183 |
+
work stoppage, computer failure or malfunction, or any and all
|
| 184 |
+
other commercial damages or losses), even if such Contributor
|
| 185 |
+
has been advised of the possibility of such damages.
|
| 186 |
+
|
| 187 |
+
9. Accepting Warranty or Additional Liability. While redistributing
|
| 188 |
+
the Work or Derivative Works thereof, You may choose to offer,
|
| 189 |
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
| 190 |
+
or other liability obligations and/or rights consistent with this
|
| 191 |
+
License. However, in accepting such obligations, You may act only
|
| 192 |
+
on Your own behalf and on Your sole responsibility, not on behalf
|
| 193 |
+
of any other Contributor, and only if You agree to indemnify,
|
| 194 |
+
defend, and hold each Contributor harmless for any liability
|
| 195 |
+
incurred by, or claims asserted against, such Contributor by reason
|
| 196 |
+
of your accepting any such warranty or additional liability.
|
| 197 |
+
|
| 198 |
+
END OF TERMS AND CONDITIONS
|
| 199 |
+
|
| 200 |
+
APPENDIX: How to apply the Apache License to your work.
|
| 201 |
+
|
| 202 |
+
To apply the Apache License to your work, attach the following
|
| 203 |
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
| 204 |
+
replaced with your own identifying information. (Don't include
|
| 205 |
+
the brackets!) The text should be enclosed in the appropriate
|
| 206 |
+
comment syntax for the file format. We also recommend that a
|
| 207 |
+
file or class name and description of purpose be included on the
|
| 208 |
+
same "printed page" as the copyright notice for easier
|
| 209 |
+
identification within third-party archives.
|
| 210 |
+
|
| 211 |
+
Copyright [yyyy] [name of copyright owner]
|
| 212 |
+
|
| 213 |
+
Licensed under the Apache License, Version 2.0 (the "License");
|
| 214 |
+
you may not use this file except in compliance with the License.
|
| 215 |
+
You may obtain a copy of the License at
|
| 216 |
+
|
| 217 |
+
http://www.apache.org/licenses/LICENSE-2.0
|
| 218 |
+
|
| 219 |
+
Unless required by applicable law or agreed to in writing, software
|
| 220 |
+
distributed under the License is distributed on an "AS IS" BASIS,
|
| 221 |
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 222 |
+
See the License for the specific language governing permissions and
|
| 223 |
+
limitations under the License.
|
README.md
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
|
| 3 |
+
license: other
|
| 4 |
+
license_name: s2-mas-controlled-research-v1.2
|
| 5 |
+
license_link: https://huggingface.co/ya9919/qwen3.5-9b-finance-lora-head-200k/blob/main/LICENSE
|
| 6 |
+
|
| 7 |
+
language:
|
| 8 |
+
|
| 9 |
+
- en
|
| 10 |
+
|
| 11 |
+
base_model: Qwen/Qwen3.5-9B
|
| 12 |
+
|
| 13 |
+
tags:
|
| 14 |
+
|
| 15 |
+
- s2-mas
|
| 16 |
+
|
| 17 |
+
- financial-qa
|
| 18 |
+
|
| 19 |
+
- decision-head
|
| 20 |
+
|
| 21 |
+
- qwen3_5
|
| 22 |
+
|
| 23 |
+
- peft
|
| 24 |
+
|
| 25 |
+
- lora
|
| 26 |
+
|
| 27 |
+
---
|
| 28 |
+
# qwen3.5-9b-finance-lora-head-200k
|
| 29 |
+
|
| 30 |
+
Paper: [S²-MAS](https://github.com/KataDavidXD/s2-mas/blob/main/paper/S2_MAS_Paper.pdf).
|
| 31 |
+
|
| 32 |
+
One of ten development-selected financial decision-model release versions in S²-MAS.
|
| 33 |
+
|
| 34 |
+
LoRA adapter plus a shared scalar decision head; obtain the official backbone separately.
|
| 35 |
+
|
| 36 |
+
Initialized from the official post-trained 9B release. The 4B/9B comparison varies both model scale and upstream training history.
|
| 37 |
+
|
| 38 |
+
## Training and selected checkpoint
|
| 39 |
+
|
| 40 |
+
- Method: `lora`.
|
| 41 |
+
|
| 42 |
+
- Distinct downstream training rows: **200,000** from the fixed decision-QA training partition.
|
| 43 |
+
|
| 44 |
+
- Initialization: [Qwen/Qwen3.5-9B](https://huggingface.co/Qwen/Qwen3.5-9B).
|
| 45 |
+
|
| 46 |
+
- This stage terminal row exposures: **200,000**; selected checkpoint stage exposures: **200,000**.
|
| 47 |
+
|
| 48 |
+
- Selected checkpoint cumulative row exposures: **200,000**; selected cumulative distinct rows: **200,000**.
|
| 49 |
+
|
| 50 |
+
- A fixed 20,000-example development set selects this checkpoint. The complete development partition (412,873 examples) selected LoRA on Qwen4B; the method was fixed before the independently initialized 9B run. The final test did not select budgets or methods.
|
| 51 |
+
|
| 52 |
+
## Held-out financial QA
|
| 53 |
+
|
| 54 |
+
Evaluation uses the fixed **240,458-record / 119-question-version common test**, with **8,275 respondent/household groups**. Both metrics retain the complete test denominator.
|
| 55 |
+
|
| 56 |
+
| Accuracy (%) | Question-macro F1 (%) | Invalid predictions |
|
| 57 |
+
|---:|---:|---:|
|
| 58 |
+
| 74.0919 | 36.6622 | 0 |
|
| 59 |
+
|
| 60 |
+
Accuracy pools correct choices across records. Question-macro F1 averages candidate-class F1 within each question version and weights versions equally; every defined answer class is included. Invalid decisions count as incorrect.
|
| 61 |
+
|
| 62 |
+
## Files and precision
|
| 63 |
+
|
| 64 |
+
- Model files: `head.pt, adapter/adapter_config.json, adapter/adapter_model.safetensors`.
|
| 65 |
+
|
| 66 |
+
- Reported common-test compute: BF16 Qwen backbone with FP32 candidate scoring.
|
| 67 |
+
|
| 68 |
+
- Obtain the official Qwen backbone and tokenizer named in the configuration separately.
|
| 69 |
+
|
| 70 |
+
- Inference scores the full state, question and complete candidate menu.
|
| 71 |
+
|
| 72 |
+
## License and access
|
| 73 |
+
|
| 74 |
+
The project model contribution is offered under the [S²-MAS Controlled Model Research License v1.2](LICENSE): noncommercial scientific use, no redistribution, and no unauthorized reverse engineering, extraction or distillation. Training and evaluation records are not distributed. Source-data access requires the provider's authorization. Permission requests: yli9919@hku.hk.
|
| 75 |
+
|
| 76 |
+
Project repository: [s2-mas](https://github.com/KataDavidXD/s2-mas).
|
adapter/adapter_config.json
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"alora_invocation_tokens": null,
|
| 3 |
+
"alpha_pattern": {},
|
| 4 |
+
"arrow_config": null,
|
| 5 |
+
"auto_mapping": {
|
| 6 |
+
"base_model_class": "Qwen3_5ForConditionalGeneration",
|
| 7 |
+
"parent_library": "transformers.models.qwen3_5.modeling_qwen3_5"
|
| 8 |
+
},
|
| 9 |
+
"base_model_name_or_path": "Qwen/Qwen3.5-9B",
|
| 10 |
+
"bias": "none",
|
| 11 |
+
"corda_config": null,
|
| 12 |
+
"ensure_weight_tying": false,
|
| 13 |
+
"eva_config": null,
|
| 14 |
+
"exclude_modules": null,
|
| 15 |
+
"fan_in_fan_out": false,
|
| 16 |
+
"inference_mode": true,
|
| 17 |
+
"init_lora_weights": true,
|
| 18 |
+
"kasa_config": null,
|
| 19 |
+
"layer_replication": null,
|
| 20 |
+
"layers_pattern": null,
|
| 21 |
+
"layers_to_transform": null,
|
| 22 |
+
"loftq_config": {},
|
| 23 |
+
"lora_alpha": 32,
|
| 24 |
+
"lora_bias": false,
|
| 25 |
+
"lora_dropout": 0.0,
|
| 26 |
+
"lora_ga_config": null,
|
| 27 |
+
"megatron_config": null,
|
| 28 |
+
"megatron_core": "megatron.core",
|
| 29 |
+
"modules_to_save": null,
|
| 30 |
+
"monteclora_config": null,
|
| 31 |
+
"peft_type": "LORA",
|
| 32 |
+
"peft_version": "0.21.2",
|
| 33 |
+
"qalora_group_size": 16,
|
| 34 |
+
"r": 16,
|
| 35 |
+
"rank_pattern": {},
|
| 36 |
+
"target_modules": [
|
| 37 |
+
"in_proj_b",
|
| 38 |
+
"q_proj",
|
| 39 |
+
"in_proj_z",
|
| 40 |
+
"o_proj",
|
| 41 |
+
"in_proj_qkv",
|
| 42 |
+
"v_proj",
|
| 43 |
+
"k_proj",
|
| 44 |
+
"in_proj_a",
|
| 45 |
+
"out_proj"
|
| 46 |
+
],
|
| 47 |
+
"target_parameters": null,
|
| 48 |
+
"task_type": null,
|
| 49 |
+
"trainable_token_indices": null,
|
| 50 |
+
"use_bdlora": null,
|
| 51 |
+
"use_dora": false,
|
| 52 |
+
"use_qalora": false,
|
| 53 |
+
"use_rslora": false,
|
| 54 |
+
"velora_config": null
|
| 55 |
+
}
|
adapter/adapter_model.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:c43813ee51e98d72d0677399d3342fa1c699fb99e6f4cbf0976d291c82d4e387
|
| 3 |
+
size 72496648
|
decision_config.json
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"base_model": "Qwen/Qwen3.5-9B",
|
| 3 |
+
"model_name": "Qwen3.5-9B",
|
| 4 |
+
"method": "lora",
|
| 5 |
+
"max_length": 2048,
|
| 6 |
+
"architecture": "last-nonpadding-L2-linear-candidate-softmax-v1",
|
| 7 |
+
"prompt_version": "full-state-question-options-focus-v1",
|
| 8 |
+
"backbone_dtype": "bfloat16",
|
| 9 |
+
"head_dtype": "float32",
|
| 10 |
+
"normalized_feature_dtype": "float32",
|
| 11 |
+
"attention_implementation": "sdpa"
|
| 12 |
+
}
|
head.pt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:4b364488fb5274542f5a624c6357f91cab4c6e69b6a84ecb35f65faaee2e483e
|
| 3 |
+
size 18281
|
qwen_decision.py
ADDED
|
@@ -0,0 +1,250 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Inference for a Qwen3.5 independent-candidate financial decision head.
|
| 2 |
+
|
| 3 |
+
The package supplies decision_config.json, head.pt, and (for ``lora``) an
|
| 4 |
+
adapter/ directory. Original Qwen weights and tokenizer are an upstream
|
| 5 |
+
dependency, supplied separately to ``DecisionPredictor.from_pretrained``.
|
| 6 |
+
|
| 7 |
+
Input rows contain ``state``, ``qid``, ``question`` (``instructions`` and an
|
| 8 |
+
ordered ``criteria`` mapping), and ordered ``candidate_ids``. Observed answers
|
| 9 |
+
and respondent identifiers are unnecessary for inference. Each candidate gets
|
| 10 |
+
its own complete sequence containing the state, question, all options, and that
|
| 11 |
+
candidate's description. No chat template is applied and no input is truncated.
|
| 12 |
+
|
| 13 |
+
Backbone inference uses BF16 and SDPA. The last nonpadding token is converted
|
| 14 |
+
to FP32 and L2-normalized. Head-only packages additionally round this feature
|
| 15 |
+
through BF16, matching their stored frozen features; LoRA packages retain the
|
| 16 |
+
normalized FP32 feature. A bias-free FP32 linear head scores candidates, and a
|
| 17 |
+
softmax over the allowed candidates produces the response distribution.
|
| 18 |
+
"""
|
| 19 |
+
from __future__ import annotations
|
| 20 |
+
|
| 21 |
+
import argparse
|
| 22 |
+
import json
|
| 23 |
+
import os
|
| 24 |
+
from pathlib import Path
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
PROMPT_VERSION = "full-state-question-options-focus-v1"
|
| 28 |
+
ARCHITECTURE = "last-nonpadding-L2-linear-candidate-softmax-v1"
|
| 29 |
+
UPSTREAM_MODELS = {
|
| 30 |
+
"Qwen3.5-4B-Base": "Qwen/Qwen3.5-4B-Base",
|
| 31 |
+
"Qwen3.5-9B": "Qwen/Qwen3.5-9B",
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
def validate_row(row):
|
| 36 |
+
"""Validate the unlabeled inference fields without changing their order."""
|
| 37 |
+
required = {"state", "qid", "question", "candidate_ids"}
|
| 38 |
+
if not isinstance(row, dict) or not required.issubset(row):
|
| 39 |
+
raise ValueError("Input requires state, qid, question, and candidate_ids")
|
| 40 |
+
ids = row["candidate_ids"]
|
| 41 |
+
if not isinstance(ids, list) or len(ids) < 2 or any(not isinstance(value, str) for value in ids):
|
| 42 |
+
raise ValueError("candidate_ids must contain at least two distinct strings")
|
| 43 |
+
if len(set(ids)) != len(ids):
|
| 44 |
+
raise ValueError("Candidate IDs must be distinct")
|
| 45 |
+
question = row["question"]
|
| 46 |
+
criteria = question.get("criteria") if isinstance(question, dict) else None
|
| 47 |
+
if not isinstance(criteria, dict) or set(criteria) != set(ids):
|
| 48 |
+
raise ValueError("Question criteria must match all allowed candidate IDs")
|
| 49 |
+
return row
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
def prompt(row, focus):
|
| 53 |
+
"""The training-time full-state/question/options/focus rendering, verbatim."""
|
| 54 |
+
question = row["question"]
|
| 55 |
+
return ("Predict this respondent's observed answer using the supplied respondent state.\n"
|
| 56 |
+
"Respondent state:\n" + json.dumps(row["state"], ensure_ascii=False) +
|
| 57 |
+
"\nQuestion:\n" + str(question.get("instructions", row["qid"])) +
|
| 58 |
+
"\nAll allowed options:\n" + json.dumps(question["criteria"], ensure_ascii=False) +
|
| 59 |
+
"\nCandidate being scored:\n" + json.dumps({"id": focus, "description": question["criteria"][focus]}, ensure_ascii=False) +
|
| 60 |
+
"\nCandidate compatibility with this respondent's answer:")
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
def encode_rows(rows, tokenizer, max_length):
|
| 64 |
+
"""Preserve complete candidate inputs and reject an insufficient window."""
|
| 65 |
+
if not rows or isinstance(max_length, bool) or not isinstance(max_length, int) or max_length < 1:
|
| 66 |
+
raise ValueError("A nonempty row batch and a positive max_length are required")
|
| 67 |
+
for row in rows:
|
| 68 |
+
validate_row(row)
|
| 69 |
+
texts = [prompt(row, candidate) for row in rows for candidate in row["candidate_ids"]]
|
| 70 |
+
encoded = tokenizer(texts, add_special_tokens=True, truncation=False, padding=False)
|
| 71 |
+
lengths = [len(value) for value in encoded["input_ids"]]
|
| 72 |
+
if max(lengths) > max_length:
|
| 73 |
+
raise ValueError(f"Complete candidate input exceeds max_length ({max(lengths)} > {max_length}); input was not truncated")
|
| 74 |
+
batch = tokenizer.pad(encoded, padding=True, return_tensors="pt")
|
| 75 |
+
return batch, [len(row["candidate_ids"]) for row in rows], max(lengths)
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
def text_model(backbone):
|
| 79 |
+
base = backbone.get_base_model() if hasattr(backbone, "get_base_model") else backbone
|
| 80 |
+
if hasattr(base, "model") and hasattr(base.model, "language_model"):
|
| 81 |
+
return base.model.language_model
|
| 82 |
+
if hasattr(base, "language_model"):
|
| 83 |
+
return base.language_model
|
| 84 |
+
raise ValueError("Cannot locate Qwen3.5 text backbone")
|
| 85 |
+
|
| 86 |
+
|
| 87 |
+
def pooled_hidden(backbone, tokens):
|
| 88 |
+
import torch
|
| 89 |
+
hidden = text_model(backbone)(**tokens, use_cache=False, return_dict=True).last_hidden_state
|
| 90 |
+
positions = tokens["attention_mask"].sum(-1) - 1
|
| 91 |
+
values = hidden[torch.arange(hidden.shape[0], device=hidden.device), positions].float()
|
| 92 |
+
return torch.nn.functional.normalize(values, dim=-1)
|
| 93 |
+
|
| 94 |
+
|
| 95 |
+
def read_config(package_path):
|
| 96 |
+
"""Read scientific inference settings, with no training/optimizer files."""
|
| 97 |
+
config = json.loads((Path(package_path) / "decision_config.json").read_text(encoding="utf-8"))
|
| 98 |
+
required = {"base_model", "model_name", "method", "max_length", "architecture", "prompt_version"}
|
| 99 |
+
if not isinstance(config, dict) or not required.issubset(config):
|
| 100 |
+
raise ValueError("decision_config.json lacks required inference fields")
|
| 101 |
+
if config["architecture"] != ARCHITECTURE or config["prompt_version"] != PROMPT_VERSION:
|
| 102 |
+
raise ValueError("Package architecture or prompt version is unsupported")
|
| 103 |
+
if config["method"] not in {"head_only", "lora"}:
|
| 104 |
+
raise ValueError("Package method must be head_only or lora")
|
| 105 |
+
if config["model_name"] not in UPSTREAM_MODELS or config["base_model"] != UPSTREAM_MODELS[config["model_name"]]:
|
| 106 |
+
raise ValueError("Package must identify its original supported Qwen3.5 dependency")
|
| 107 |
+
length = config["max_length"]
|
| 108 |
+
if isinstance(length, bool) or not isinstance(length, int) or length < 1:
|
| 109 |
+
raise ValueError("Package max_length must be a positive integer")
|
| 110 |
+
expected_precision = {"backbone_dtype": "bfloat16", "head_dtype": "float32",
|
| 111 |
+
"normalized_feature_dtype": "bfloat16" if config["method"] == "head_only" else "float32",
|
| 112 |
+
"attention_implementation": "sdpa"}
|
| 113 |
+
for field, expected in expected_precision.items():
|
| 114 |
+
if field in config and config[field] != expected:
|
| 115 |
+
raise ValueError(f"Unsupported precision setting: {field}")
|
| 116 |
+
return config
|
| 117 |
+
|
| 118 |
+
|
| 119 |
+
class DecisionPredictor:
|
| 120 |
+
"""A loaded upstream backbone plus the package's learned decision head."""
|
| 121 |
+
def __init__(self, tokenizer, backbone, head, config, device):
|
| 122 |
+
self.tokenizer, self.backbone, self.head = tokenizer, backbone, head
|
| 123 |
+
self.config, self.device = config, device
|
| 124 |
+
|
| 125 |
+
@classmethod
|
| 126 |
+
def from_pretrained(cls, package_path, upstream_model, *, device="cuda", local_files_only=False):
|
| 127 |
+
"""Load a local decision package and its explicitly supplied dependency.
|
| 128 |
+
|
| 129 |
+
``upstream_model`` is the official repository named in the config or a
|
| 130 |
+
local directory containing those upstream weights and tokenizer.
|
| 131 |
+
``local_files_only=True`` requires the dependency to be cached locally.
|
| 132 |
+
"""
|
| 133 |
+
os.environ.setdefault("TOKENIZERS_PARALLELISM", "false")
|
| 134 |
+
os.environ.setdefault("TORCHDYNAMO_DISABLE", "1")
|
| 135 |
+
os.environ.setdefault("USE_HUB_KERNELS", "0")
|
| 136 |
+
import torch
|
| 137 |
+
from transformers import AutoTokenizer, Qwen3_5ForConditionalGeneration
|
| 138 |
+
|
| 139 |
+
package_path = Path(package_path)
|
| 140 |
+
config = read_config(package_path)
|
| 141 |
+
upstream_model = str(upstream_model)
|
| 142 |
+
if not Path(upstream_model).is_dir() and upstream_model != config["base_model"]:
|
| 143 |
+
raise ValueError("Supplied upstream repository differs from decision_config.json")
|
| 144 |
+
adapter = package_path / "adapter"
|
| 145 |
+
adapter_present = (adapter / "adapter_config.json").is_file()
|
| 146 |
+
if config["method"] == "lora" and not adapter_present:
|
| 147 |
+
raise ValueError("LoRA package is missing its adapter configuration")
|
| 148 |
+
if config["method"] == "head_only" and adapter.exists():
|
| 149 |
+
raise ValueError("Head-only package unexpectedly contains an adapter directory")
|
| 150 |
+
saved = torch.load(package_path / "head.pt", map_location="cpu", weights_only=True)
|
| 151 |
+
if not isinstance(saved, dict) or any(field not in saved for field in
|
| 152 |
+
("head_state_dict", "hidden_size", "model_name", "architecture", "prompt_version")):
|
| 153 |
+
raise ValueError("head.pt lacks required head fields")
|
| 154 |
+
for field in ("model_name", "architecture", "prompt_version"):
|
| 155 |
+
if saved[field] != config[field]:
|
| 156 |
+
raise ValueError(f"Head metadata differs from package config: {field}")
|
| 157 |
+
width = saved["hidden_size"]
|
| 158 |
+
weights = saved["head_state_dict"]
|
| 159 |
+
if (isinstance(width, bool) or not isinstance(width, int) or width < 1
|
| 160 |
+
or not isinstance(weights, dict) or set(weights) != {"weight"}
|
| 161 |
+
or not isinstance(weights["weight"], torch.Tensor)
|
| 162 |
+
or tuple(weights["weight"].shape) != (1, width)
|
| 163 |
+
or weights["weight"].dtype != torch.float32
|
| 164 |
+
or not bool(torch.isfinite(weights["weight"]).all())):
|
| 165 |
+
raise ValueError("Head must contain one finite FP32 bias-free linear weight")
|
| 166 |
+
device = torch.device(device)
|
| 167 |
+
tokenizer = AutoTokenizer.from_pretrained(upstream_model, local_files_only=local_files_only)
|
| 168 |
+
tokenizer.padding_side = "right"
|
| 169 |
+
if tokenizer.pad_token_id is None:
|
| 170 |
+
tokenizer.pad_token = tokenizer.eos_token
|
| 171 |
+
backbone = Qwen3_5ForConditionalGeneration.from_pretrained(
|
| 172 |
+
upstream_model, local_files_only=local_files_only, dtype=torch.bfloat16,
|
| 173 |
+
device_map={"": str(device)}, attn_implementation="sdpa")
|
| 174 |
+
backbone.requires_grad_(False)
|
| 175 |
+
if backbone.config.text_config.hidden_size != width:
|
| 176 |
+
raise ValueError("Upstream hidden size differs from the decision head")
|
| 177 |
+
if config["method"] == "lora":
|
| 178 |
+
from peft import PeftModel
|
| 179 |
+
# PEFT's default adapter dtype handling matches the evaluation runner.
|
| 180 |
+
backbone = PeftModel.from_pretrained(backbone, adapter, is_trainable=False)
|
| 181 |
+
backbone.eval()
|
| 182 |
+
head = torch.nn.Linear(width, 1, bias=False, dtype=torch.float32)
|
| 183 |
+
head.load_state_dict(weights, strict=True)
|
| 184 |
+
head.requires_grad_(False)
|
| 185 |
+
head.to(device).eval()
|
| 186 |
+
return cls(tokenizer, backbone, head, config, device)
|
| 187 |
+
|
| 188 |
+
def predict(self, rows, *, row_batch_size=4, candidate_batch_size=16):
|
| 189 |
+
"""Return ordered logits, probabilities, and the highest-scoring choice.
|
| 190 |
+
|
| 191 |
+
Candidate sequences occupy independent batch entries. Batching changes
|
| 192 |
+
only forward scheduling; it never combines candidates into one sequence.
|
| 193 |
+
"""
|
| 194 |
+
import torch
|
| 195 |
+
single = isinstance(rows, dict)
|
| 196 |
+
rows = [rows] if single else list(rows)
|
| 197 |
+
if row_batch_size < 1 or candidate_batch_size < 1:
|
| 198 |
+
raise ValueError("Forward batch sizes must be positive")
|
| 199 |
+
predictions = []
|
| 200 |
+
with torch.inference_mode():
|
| 201 |
+
for start in range(0, len(rows), row_batch_size):
|
| 202 |
+
selected_rows = rows[start:start + row_batch_size]
|
| 203 |
+
tokens, counts, _ = encode_rows(selected_rows, self.tokenizer, self.config["max_length"])
|
| 204 |
+
flat_scores = []
|
| 205 |
+
for offset in range(0, tokens["input_ids"].shape[0], candidate_batch_size):
|
| 206 |
+
chosen = slice(offset, offset + candidate_batch_size)
|
| 207 |
+
batch_length = int(tokens["attention_mask"][chosen].sum(-1).max())
|
| 208 |
+
batch = {key: value[chosen, :batch_length].to(self.device) for key, value in tokens.items()}
|
| 209 |
+
features = pooled_hidden(self.backbone, batch)
|
| 210 |
+
if self.config["method"] == "head_only":
|
| 211 |
+
features = features.to(torch.bfloat16).float()
|
| 212 |
+
flat_scores.append(self.head(features).squeeze(-1))
|
| 213 |
+
scores = torch.cat(flat_scores)
|
| 214 |
+
if not bool(torch.isfinite(scores).all()):
|
| 215 |
+
raise FloatingPointError("A valid candidate has a nonfinite score")
|
| 216 |
+
for row, logits in zip(selected_rows, scores.split(counts)):
|
| 217 |
+
index = int(logits.argmax())
|
| 218 |
+
predictions.append({"qid": row["qid"], "candidate_ids": list(row["candidate_ids"]),
|
| 219 |
+
"logits": logits.cpu().tolist(),
|
| 220 |
+
"probabilities": logits.softmax(dim=-1).cpu().tolist(),
|
| 221 |
+
"prediction_index": index,
|
| 222 |
+
"prediction": row["candidate_ids"][index]})
|
| 223 |
+
return predictions[0] if single else predictions
|
| 224 |
+
|
| 225 |
+
|
| 226 |
+
def main():
|
| 227 |
+
parser = argparse.ArgumentParser(description=__doc__)
|
| 228 |
+
parser.add_argument("--package", type=Path, required=True)
|
| 229 |
+
parser.add_argument("--upstream-model", required=True)
|
| 230 |
+
parser.add_argument("--input", type=Path, required=True, help="JSON row or JSON list of rows")
|
| 231 |
+
parser.add_argument("--output", type=Path, help="Default: print JSON to stdout")
|
| 232 |
+
parser.add_argument("--device", default="cuda")
|
| 233 |
+
parser.add_argument("--local-files-only", action="store_true")
|
| 234 |
+
parser.add_argument("--row-batch-size", type=int, default=4)
|
| 235 |
+
parser.add_argument("--candidate-batch-size", type=int, default=16)
|
| 236 |
+
args = parser.parse_args()
|
| 237 |
+
rows = json.loads(args.input.read_text(encoding="utf-8"))
|
| 238 |
+
predictor = DecisionPredictor.from_pretrained(args.package, args.upstream_model,
|
| 239 |
+
device=args.device, local_files_only=args.local_files_only)
|
| 240 |
+
result = predictor.predict(rows, row_batch_size=args.row_batch_size,
|
| 241 |
+
candidate_batch_size=args.candidate_batch_size)
|
| 242 |
+
output = json.dumps(result, ensure_ascii=False, indent=2) + "\n"
|
| 243 |
+
if args.output:
|
| 244 |
+
args.output.write_text(output, encoding="utf-8")
|
| 245 |
+
else:
|
| 246 |
+
print(output, end="")
|
| 247 |
+
|
| 248 |
+
|
| 249 |
+
if __name__ == "__main__":
|
| 250 |
+
main()
|
release_metadata.json
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"metadata_role": "Publication metadata; not model configuration.",
|
| 3 |
+
"model_id": "ya9919/qwen3.5-9b-finance-lora-head-200k",
|
| 4 |
+
"model_family": "Qwen3.5-9B post-trained",
|
| 5 |
+
"method": "lora",
|
| 6 |
+
"initialization_model": "Qwen/Qwen3.5-9B",
|
| 7 |
+
"unique_downstream_training_rows": 200000,
|
| 8 |
+
"stage_terminal_row_exposures": 200000,
|
| 9 |
+
"selected_stage_row_exposures": 200000,
|
| 10 |
+
"selected_cumulative_row_exposures": 200000,
|
| 11 |
+
"checkpoint_selection": "Fixed 20,000-example development set selects the checkpoint.",
|
| 12 |
+
"method_selection": "The complete 412,873-example development partition compares the two 200k Qwen4B methods (head-only versus LoRA). The selected LoRA method is fixed before the independently initialized Qwen9B run; the final test does not select budgets or methods.",
|
| 13 |
+
"test": {
|
| 14 |
+
"rows": 240458,
|
| 15 |
+
"question_versions": 119,
|
| 16 |
+
"respondent_groups": 8275,
|
| 17 |
+
"accuracy_percent": 74.0919,
|
| 18 |
+
"question_macro_f1_percent": 36.6622,
|
| 19 |
+
"invalid_predictions": 0
|
| 20 |
+
},
|
| 21 |
+
"evaluation_compute_precision": "BF16 Qwen backbone with FP32 candidate scoring",
|
| 22 |
+
"license": "other",
|
| 23 |
+
"license_name": "S²-MAS Controlled Model Research License v1.2",
|
| 24 |
+
"license_link": "https://huggingface.co/ya9919/qwen3.5-9b-finance-lora-head-200k/blob/main/LICENSE"
|
| 25 |
+
}
|