-
Notifications
You must be signed in to change notification settings - Fork 944
Adds ability to load quantized weights by de-quantizing them. #965
Conversation
Thanks for doing this! Can you go talk to Suharsh and make sure this approach seems reasonable to him? Specifically I want to make sure 0s are 0s (which means you may have to use scale / offset). Review status: 0 of 1 files reviewed at latest revision, all discussions resolved, some commit checks failed. src/weights_loader.ts, line 128 at r1 (raw file):
this should not be removed Comments from Reviewable |
Looks great! One comment to reduce number of intermediate allocated arrays, and after that I'm very happy to get this in! Review status: 0 of 2 files reviewed at latest revision, 1 unresolved discussion, some commit checks failed. src/weights_loader.ts, line 178 at r3 (raw file):
no need to have this intermediate Float32Array. Just allocate the final Then iterate directly over the UIn8Array or UInt16Array (depending on the quantized dtype), and do the math directly there. const quantized = new Uint8Array(byteBuffer); // or UInt16Array
const typedArray = new Float32Array(quantized.length); // or Int32Array
for (let i = 0; i < a.length; i++) {
typedArray[i] = quantized[i] * scale + min;
} Comments from Reviewable |
Review status: 0 of 2 files reviewed at latest revision, 2 unresolved discussions, some commit checks failed. src/weights_loader.ts, line 178 at r3 (raw file): Previously, dsmilkov (Daniel Smilkov) wrote…
Forgot to say , if it's int32, round before you assign to typedArray[i] Comments from Reviewable |
Review status: 0 of 2 files reviewed at latest revision, 2 unresolved discussions, some commit checks failed. src/weights_loader.ts, line 128 at r1 (raw file): Previously, nsthorat (Nikhil Thorat) wrote…
Done. src/weights_loader.ts, line 178 at r3 (raw file): Previously, dsmilkov (Daniel Smilkov) wrote…
Done. Comments from Reviewable |
Done. Review status: 0 of 2 files reviewed at latest revision, 2 unresolved discussions. Comments from Reviewable |
Thanks! Review status: 0 of 2 files reviewed at latest revision, 2 unresolved discussions. src/weights_loader.ts, line 31 at r4 (raw file):
Just a suggestion: Having src/weights_loader.ts, line 195 at r4 (raw file):
Perhaps be more specific: "weight ... has a dtype unsupported by quantization ..." src/weights_loader_test.ts, line 470 at r4 (raw file):
Add another test of a mixed weight manifest, wherein some weights have quantization, others don't. Comments from Reviewable |
Review status: 0 of 2 files reviewed at latest revision, 5 unresolved discussions. src/weights_loader.ts, line 31 at r4 (raw file): Previously, caisq (Shanqing Cai) wrote…
I originally had min/max but needed to switch when we added nudging since min and max is no longer enough information to dequantize. Added doc. src/weights_loader.ts, line 195 at r4 (raw file): Previously, caisq (Shanqing Cai) wrote…
Done. src/weights_loader_test.ts, line 470 at r4 (raw file): Previously, caisq (Shanqing Cai) wrote…
Done. Comments from Reviewable |
Reviewed 1 of 2 files at r4. src/weights_loader.ts, line 187 at r4 (raw file):
use typeArray = Float32Array.from(quantizedArray, v => v * quantization.scale + quantization.min), same for int32 case. Comments from Reviewable |
Review status: 0 of 2 files reviewed at latest revision, 6 unresolved discussions, all commit checks successful. Comments from Reviewable |
Reviewed 1 of 2 files at r4. Comments from Reviewable |
Reviewed 2 of 2 files at r5. src/weights_loader.ts, line 187 at r4 (raw file): Previously, pyu10055 (Ping Yu) wrote…
+1. This will create one less intermediate array Comments from Reviewable |
Review status: all files reviewed at latest revision, 6 unresolved discussions, all commit checks successful. src/weights_loader.ts, line 187 at r4 (raw file): Previously, dsmilkov (Daniel Smilkov) wrote…
Done. Comments from Reviewable |
Works in conjunction with tensorflow/tfjs-converter#87.
This change is