-
Notifications
You must be signed in to change notification settings - Fork 950
Add basic types and helper methods for model exporting #990
Conversation
src/io/io_utils.ts
Outdated
|
||
if (tensor.dtype !== 'float32' && tensor.dtype !== 'int32' && | ||
tensor.dtype !== 'bool') { | ||
throw new Error(`Unsupported dtype: ${tensor.dtype}`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we include the name of the tensor here as well.
src/io/io_utils.ts
Outdated
bytes = numel; | ||
value = tensor(new Uint8Array(buffer, offset, numel), shape, 'bool'); | ||
} else { | ||
throw new Error(`Unsupported dtype: ${dtype}`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As above, please include the name fields as well.
} else if (x as any instanceof Uint8Array) { | ||
totalByteLength += x.length; | ||
} else { | ||
throw new Error(`Unsupported TypedArray subtype: ${x.constructor.name}`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are there minification concerns here with constructor.name?
Review status: 0 of 6 files reviewed at latest revision, 3 unresolved discussions. src/io/io_utils.ts, line 3 at r1 (raw file):
LLC src/io/io_utils.ts, line 39 at r1 (raw file):
This shadows the imported tensor() function; can you use a different name? Comments from Reviewable |
Really nice work. To give more context to our external contributions, can you add a short description in this PR for what the changes are and how you plan to use Reviewed 7 of 10 files at r1. src/index.ts, line 37 at r1 (raw file):
add a newline here to separate serialization from optimizers. src/io/io_utils.ts, line 18 at r1 (raw file):
since this is not a test, avoid importing directly from src/io/io_utils.ts, line 34 at r1 (raw file):
How about calling it something more descriptive like src/io/io_utils.ts, line 35 at r1 (raw file):
instead of a tuple, it's better to return an object for readability. Perhaps: src/io/io_utils.ts, line 37 at r1 (raw file):
use the alias in src/io/io_utils.ts, line 72 at r1 (raw file):
util.sizeFromShape(shape) src/io/io_utils.ts, line 100 at r1 (raw file):
use TypedArray in types.ts (alias for all these arrays) src/io/io_utils.ts, line 104 at r1 (raw file):
when do null and undefined happen? Better to throw an error in that case and let the caller figure it out src/io/io_utils.ts, line 114 at r1 (raw file):
strange that you need to cast to src/io/io_utils_test.ts, line 22 at r1 (raw file):
if these are exposed to the users, use public API (import from index) src/io/types.ts, line 83 at r1 (raw file):
no need for this TODO, since you can always add more fields everywhere ;) Comments from Reviewable |
typo: external contributors* Review status: 5 of 6 files reviewed at latest revision, 16 unresolved discussions. Comments from Reviewable |
Review status: 5 of 6 files reviewed at latest revision, 16 unresolved discussions. src/index.ts, line 36 at r1 (raw file):
just a note to double-check that it is necessary for all these types to be exposed to public api. Want to make sure we don't expose things that are meant to be implementation detail Comments from Reviewable |
Review status: 5 of 6 files reviewed at latest revision, 17 unresolved discussions. src/io/types.ts, line 99 at r1 (raw file):
s/resposnes/responses Comments from Reviewable |
Review status: 5 of 6 files reviewed at latest revision, 18 unresolved discussions, some commit checks failed. src/io/io_utils.ts, line 32 at r1 (raw file):
want to point out this method will only work for encode weights, the activation tensors could have multiple outputs, they are identified by the name + index. maybe better to rename to encodeWeights and decodeWeights? src/io/io_utils.ts, line 34 at r1 (raw file):
Also, how different is this code from the loadWeights method, are there plan to merge those two? Comments from Reviewable |
Review status: 5 of 6 files reviewed at latest revision, 20 unresolved discussions. src/index.ts, line 36 at r1 (raw file): Previously, dsmilkov (Daniel Smilkov) wrote…
Done double checking. These are all needed by implementation in tfjs-layer. src/index.ts, line 37 at r1 (raw file): Previously, dsmilkov (Daniel Smilkov) wrote…
Done. src/io/io_utils.ts, line 3 at r1 (raw file): Previously, davidsoergel (David Soergel) wrote…
Done making this change throughout src/io/ src/io/io_utils.ts, line 18 at r1 (raw file): Previously, dsmilkov (Daniel Smilkov) wrote…
Done. src/io/io_utils.ts, line 32 at r1 (raw file):
Good point. In TensorFlow and TensorFlow.js, non-weight tensors generally don't have names. So src/io/io_utils.ts, line 34 at r1 (raw file): Previously, dsmilkov (Daniel Smilkov) wrote…
The Considering Ping's comment, I'll rename the methods to src/io/io_utils.ts, line 34 at r1 (raw file): Previously, pyu10055 (Ping Yu) wrote…
Yes, I also added TODO items to handle quantization to these methods. cc @adarob src/io/io_utils.ts, line 35 at r1 (raw file): Previously, dsmilkov (Daniel Smilkov) wrote…
Done. I'm using the field names src/io/io_utils.ts, line 37 at r1 (raw file): Previously, dsmilkov (Daniel Smilkov) wrote…
Done. src/io/io_utils.ts, line 39 at r1 (raw file): Previously, davidsoergel (David Soergel) wrote…
Good point. Done. Using src/io/io_utils.ts, line 43 at r1 (raw file): Previously, ericdnielsen wrote…
Done. src/io/io_utils.ts, line 72 at r1 (raw file): Previously, dsmilkov (Daniel Smilkov) wrote…
Done. src/io/io_utils.ts, line 88 at r1 (raw file): Previously, ericdnielsen wrote…
Done. src/io/io_utils.ts, line 100 at r1 (raw file): Previously, dsmilkov (Daniel Smilkov) wrote…
Done. src/io/io_utils.ts, line 104 at r1 (raw file): Previously, dsmilkov (Daniel Smilkov) wrote…
I removed the logic for null and undefined here and throw an error as you suggested. src/io/io_utils.ts, line 114 at r1 (raw file): Previously, dsmilkov (Daniel Smilkov) wrote…
This is because we are testing things that shouldn't happen in TypeScript because of type checking, i.e., things that can happen only in JavaScript. src/io/io_utils.ts, line 120 at r1 (raw file): Previously, ericdnielsen wrote…
Good question. The input here is a subtype of TypedArray, i.e., a built-in type. So most likely, there will be no minification of the constructor. src/io/io_utils_test.ts, line 22 at r1 (raw file): Previously, dsmilkov (Daniel Smilkov) wrote…
Done. src/io/types.ts, line 83 at r1 (raw file): Previously, dsmilkov (Daniel Smilkov) wrote…
Done. src/io/types.ts, line 99 at r1 (raw file): Previously, dsmilkov (Daniel Smilkov) wrote…
Done. Comments from Reviewable |
Reviewed 2 of 8 files at r2. src/io/io_utils.ts, line 18 at r1 (raw file): Previously, caisq (Shanqing Cai) wrote…
I still see index src/io/io_utils.ts, line 72 at r1 (raw file): Previously, caisq (Shanqing Cai) wrote…
can you just use size instead of numel src/io/io_utils.ts, line 27 at r2 (raw file):
would be good to mention how this is supposed to be symmetric to our other functionality. Would also be good to say this does not shard. src/io/io_utils.ts, line 80 at r2 (raw file):
we have a map you can use: Comments from Reviewable |
Reviewed 6 of 8 files at r2. src/io/io_utils.ts, line 107 at r2 (raw file):
use forEach since it's a list. This way the tsc won't need to compile this into es5 compatible code. Comments from Reviewable |
Review status: all files reviewed at latest revision, 16 unresolved discussions, all commit checks successful. src/io/io_utils.ts, line 18 at r1 (raw file): Previously, nsthorat (Nikhil Thorat) wrote…
Done. src/io/io_utils.ts, line 72 at r1 (raw file): Previously, nsthorat (Nikhil Thorat) wrote…
Done. src/io/io_utils.ts, line 27 at r2 (raw file): Previously, nsthorat (Nikhil Thorat) wrote…
Done. src/io/io_utils.ts, line 107 at r2 (raw file): Previously, dsmilkov (Daniel Smilkov) wrote…
Done. Comments from Reviewable |
Including loadWeights.
Review status: 0 of 7 files reviewed at latest revision, 16 unresolved discussions, all commit checks successful. src/index.ts, line 67 at r3 (raw file):
move io here, so we have all second level exports together Comments from Reviewable |
Review status: 0 of 7 files reviewed at latest revision, 17 unresolved discussions, all commit checks successful. src/index.ts, line 67 at r3 (raw file): Previously, dsmilkov (Daniel Smilkov) wrote…
Done. Comments from Reviewable |
Towards tensorflow/tfjs#13
This change is