Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[tools] introduce circle plus generator #12977

Merged
merged 5 commits into from May 14, 2024

Conversation

zetwhite
Copy link
Contributor

@zetwhite zetwhite commented May 9, 2024

This introduces a circle plus generator, which helps handle a circle file with training hyperparameters.
As a first feature, it checks whether a circle file contains training parameters or not.

ONE-DCO-1.0-Signed-off-by: seunghui youn sseung.youn@samsung.com

@zetwhite zetwhite force-pushed the 0509/circlep_check branch 4 times, most recently from 483bf38 to 9237f7d Compare May 9, 2024 13:53
@zetwhite zetwhite added the approval: 2 Require at least 2 approvals label May 9, 2024

## Inject training parameters using json file

<!--to be updated -->
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll add this feature in next PR

tools/circle_plus_gen/lib/train_info.py Outdated Show resolved Hide resolved
tools/circle_plus_gen/lib/train_info.py Outdated Show resolved Hide resolved
@zetwhite zetwhite force-pushed the 0509/circlep_check branch 2 times, most recently from 47ea7c2 to 1926ede Compare May 9, 2024 14:18
This introduces a circle plus generator, which helps handle a circle file with training hyperparameters.
As a first feature, it checks whether a circle file contains training parameters or not.

ONE-DCO-1.0-Signed-off-by: seunghui youn <sseung.youn@samsung.com>
@hseok-oh
Copy link
Contributor

@zetwhite Could you reduce example model file size? (under 5KB if possible)

BTW, I failed to open example model on circledump and netron.

 ./build/out/bin/circledump tools/circle_plus_gen/example/mnist.circle 
Dump: tools/circle_plus_gen/example/mnist.circle

Segmentation fault (core dumped)

@jyoungyun
Copy link
Contributor

jyoungyun commented May 13, 2024

Good~ This PR looks good to me :)

The attached mnist_with_tparam.circle file contains CTR1 for TRAINING_FILE_IDENTIFIER. Please use this PR to regenerate the circle file.

(added)
To recognize the mnist_with_tparam.circle file in the circle format, the CIR0 file identifier must be added when exporting the new circle file.

And the mnist.circle seems to be corrupt. Please check this file too.

details

mnist_with_tparam.circle file

00000000: 1800 0000 0000 1200 1800 0000 1400 1000  ................
...
00000050: 4349 5243 4c45 5f54 5241 494e 494e 4700  CIRCLE_TRAINING.
00000060: 0b00 0000 485b 0300 405b 0300 304b 0000  ....H[..@[..0K..
...
000000a0: 4354 5231 0000 1600 2000 1c00 0000 1b00  CTR1.... .......

correct file

00000000: 1c00 0000 4349 5230 0000 1200 1800 0000  ....CIR0........
...
00000050: 0f00 0000 4349 5243 4c45 5f54 5241 494e  ....CIRCLE_TRAIN
00000060: 494e 4700 2200 0000 6439 0000 5c39 0000  ING."...d9..\9..
...
000000f0: 76c6 ffff 0400 0000 9400 0000 2400 0000  v...........$...
00000100: 4354 5230 0000 1a00 2400 2000 1f00 1e00  CTR0....$. .....

mhs4670go
mhs4670go previously approved these changes May 13, 2024
tools/circle_plus_gen/README.md Outdated Show resolved Hide resolved
tools/circle_plus_gen/README.md Outdated Show resolved Hide resolved
tools/circle_plus_gen/lib/circle_plus.py Outdated Show resolved Hide resolved
tools/circle_plus_gen/main.py Outdated Show resolved Hide resolved
tools/circle_plus_gen/main.py Show resolved Hide resolved
tools/circle_plus_gen/lib/train_info.py Outdated Show resolved Hide resolved
tools/circle_plus_gen/README.md Outdated Show resolved Hide resolved
tools/circle_plus_gen/README.md Outdated Show resolved Hide resolved
@zetwhite zetwhite added the PR/NO MERGE Please don't merge. I'm still working on this :) label May 13, 2024
@zetwhite
Copy link
Contributor Author

I'm still updating this PR. I'll re-request the review explicitly if it is ready.

@zetwhite zetwhite force-pushed the 0509/circlep_check branch 3 times, most recently from b99872e to b252485 Compare May 13, 2024 11:37
@zetwhite zetwhite removed the PR/NO MERGE Please don't merge. I'm still working on this :) label May 13, 2024
@zetwhite
Copy link
Contributor Author

@zetwhite Could you reduce example model file size? (under 5KB if possible)

BTW, I failed to open example model on circledump and netron.

@hseok-oh I replace circle files with smaller-sized ones. Now it's about 1KiB.
I also checked it opened well in my local env, Could you try again?

@zetwhite
Copy link
Contributor Author

@jyoungyun @ragmani I updated PR based on code reviews. Could you take another look?

@mhs4670go Thank you a lot for the detailed reviews! Thanks to your review(especially about SRP rules), I could get a much better code. Pleas take another look.


2. Install required pakcages.

Currently, only `flatbuffers==24.3.25` is needed.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Currently, only `flatbuffers==24.3.25` is needed.
Currently, only `flatbuffers` is needed.

I think this tool does not require a specific flatbuffers version, doesn't it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this tool does not require a specific flatbuffers version, doesn't it?

Maybe.
But I couldn't guarantee that it works well with other versions.

So, How about

  • removing the version in README.md (because we don't have to emphasize the version in readme)
  • keeping the version in requirements.txt (because specifying the working well version is necessary)

@jyoungyun
Copy link
Contributor

The attached sample_tparam.circle still has an error when opening this file using netron. This file does not contain CIR0 to distinguish the circle file. When creating the circle file, the circle file identifier(CIR0) must be used. Please refer to the code below.

        builder.Finish(self.modelT.Pack(builder), self.CIRCLE_FILE_IDENTIFIER)
        with open(fname, 'wb') as f:
            f.write(builder.Output())

tools/circle_plus_gen/main.py Outdated Show resolved Hide resolved
tools/circle_plus_gen/main.py Outdated Show resolved Hide resolved
'''
print(f"check hyperparameters in {in_circle_file}")

circle_model: CirclePlus = CirclePlus.from_file(in_circle_file)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any reason to write the type explicitly?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No special reason.
I thought that.. writing type here helps the reader not to read the inside of CirclePlus.from_file.

tools/circle_plus_gen/schema/__init__.py Outdated Show resolved Hide resolved
tools/circle_plus_gen/schema/__init__.py Outdated Show resolved Hide resolved
@zetwhite
Copy link
Contributor Author

The attached sample_tparam.circle still has an error when opening this file using netron. This file does not contain CIR0 to distinguish the circle file. When creating the circle file, the circle file identifier(CIR0) must be used. Please refer to the code below

@jyoungyun sorry for your double-checks. There might be no problem this time. I uploaded it again and thank you for your thoughtful review. 😄

ONE_second on  0509/circlep_check [$?] …
➜ xxd tools/circle_plus_gen/example/sample_tpram.circle 
00000000: 1c00 0000 4349 5230 0000 1200 1800 0000  ....CIR0........
00000010: 1400 1000 0c00 0800 0000 0400 1200 0000  ................
00000020: 1400 0000 4000 0000 e003 0000 f403 0000  ....@...........
00000030: a805 0000 0100 0000 0c00 0000 0800 0c00  ................
00000040: 0800 0400 0800 0000 0600 0000 0400 0000  ................
00000050: 0f00 0000 4349 5243 4c45 5f54 5241 494e  ....CIRCLE_TRAIN
00000060: 494e 4700 0700 0000 9c03 0000 9403 0000  ING.............
00000070: 0401 0000 f400 0000 d400 0000 7000 0000  ............p...

Copy link
Contributor

@ragmani ragmani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

Copy link
Contributor

@jyoungyun jyoungyun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jyoungyun sorry for your double-checks. There might be no problem this time. I uploaded it again and thank you for your thoughtful review. 😄

This file works well. This code looks good to me. :)

Copy link
Contributor

@hseok-oh hseok-oh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@zetwhite
Copy link
Contributor Author

@hseok-oh could you merge this one?
@mhs4670go is out of the office this week, so it might be hard to get his approval soon.

#
# * flatc version 23.5.26 is used
# ./flatc --python --gen-onefile --gen-object-api ../../../nnpackage/schema/circle_schema.fbs
# ./flatc --python --gen-onefile --one-object-api ../../../runtime/libs/circle-schema/include/circle_traininfo.fbs
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# ./flatc --python --gen-onefile --one-object-api ../../../runtime/libs/circle-schema/include/circle_traininfo.fbs
# ./flatc --python --gen-onefile --gen-object-api ../../../runtime/libs/circle-schema/include/circle_traininfo.fbs

typo again.. I'll fix it in next PR.

@hseok-oh hseok-oh merged commit 87506c7 into Samsung:master May 14, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approval: 2 Require at least 2 approvals
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants