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

[LoRA] feat/ add LoRA to fc_layer @open sesame 03/07 10:42 #2442

Merged
merged 9 commits into from
Apr 4, 2024

Conversation

EunjuYang
Copy link
Contributor

@EunjuYang EunjuYang commented Jan 31, 2024

(Update)
This PR contains commits to

  • Add a new feature LoRA to fc_layer.
    • Add a new property : LoraRank (PositiveIntegerProperty)
    • Update forward func.
    • Update calcGradient func.
    • Update calcDerivative func.
  • Update node_exporter of fully connected layer (to pass tflite test)

2024/03/06

  • revise forwarding function
    • (W + A@B)x ➡️ Wx + (A@B)x
  • forwarding_lora is deleted
  • Test with an application: two fc-layer w/ LoRA

Self evaluation:

  1. Build test: [X]Passed [ ]Failed [ ]Skipped
  2. Run test: [X]Passed [ ]Failed [ ]Skipped

@taos-ci
Copy link
Collaborator

taos-ci commented Jan 31, 2024

📝 TAOS-CI Version: 1.5.20200925. Thank you for submitting PR #2442. Please a submit 1commit/1PR (one commit per one PR) policy to get comments quickly from reviewers. Your PR must pass all verificiation processes of cibot before starting a review process from reviewers. If you are new member to join this project, please read manuals in documentation folder and wiki page. In order to monitor a progress status of your PR in more detail, visit http://ci.nnstreamer.ai/.

Copy link
Collaborator

@taos-ci taos-ci left a comment

Choose a reason for hiding this comment

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

@EunjuYang, 💯 All CI checkers are successfully verified. Thanks.

nntrainer/layers/fc_layer.cpp Outdated Show resolved Hide resolved
@@ -186,6 +237,11 @@ void FullyConnectedLayer::incremental_forwarding(RunLayerContext &context,
}
}

/**
Copy link
Contributor

Choose a reason for hiding this comment

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

Please describe in header file

nntrainer/layers/fc_layer.cpp Outdated Show resolved Hide resolved
nntrainer/layers/fc_layer.cpp Outdated Show resolved Hide resolved
Copy link
Contributor

@lhs8928 lhs8928 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
Collaborator

@taos-ci taos-ci left a comment

Choose a reason for hiding this comment

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

@EunjuYang, 💯 All CI checkers are successfully verified. Thanks.

Copy link
Contributor

@baek2sm baek2sm left a comment

Choose a reason for hiding this comment

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

LGTM

@taos-ci
Copy link
Collaborator

taos-ci commented Mar 6, 2024

:octocat: cibot: @EunjuYang, nntrainer/layers/fc_layer.cpp does not include Doxygen tags such as @file @brief @author @bug. You must include the Doxygen tags in the source code. Please refer to a Doxygen manual at http://github.com/nnstreamer/TAOS-CI/blob/main/ci/doc/doxygen-documentation.md

Copy link
Collaborator

@taos-ci taos-ci left a comment

Choose a reason for hiding this comment

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

@EunjuYang, 💯 All CI checkers are successfully verified. Thanks.

@DonghakPark DonghakPark changed the title [LoRA] feat/ add LoRA to fc_layer [LoRA] feat/ add LoRA to fc_layer @open sesame 03/07 10:42 Mar 7, 2024
@taos-ci
Copy link
Collaborator

taos-ci commented Mar 7, 2024

:octocat: cibot: @EunjuYang, nntrainer/layers/fc_layer.cpp does not include Doxygen tags such as @file @brief @author @bug. You must include the Doxygen tags in the source code. Please refer to a Doxygen manual at http://github.com/nnstreamer/TAOS-CI/blob/main/ci/doc/doxygen-documentation.md

Copy link
Collaborator

@taos-ci taos-ci left a comment

Choose a reason for hiding this comment

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

@EunjuYang, 💯 All CI checkers are successfully verified. Thanks.

Copy link
Collaborator

@taos-ci taos-ci left a comment

Choose a reason for hiding this comment

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

@EunjuYang, 💯 All CI checkers are successfully verified. Thanks.

Copy link
Collaborator

@taos-ci taos-ci left a comment

Choose a reason for hiding this comment

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

@EunjuYang, 💯 All CI checkers are successfully verified. Thanks.

Copy link
Collaborator

@taos-ci taos-ci left a comment

Choose a reason for hiding this comment

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

@EunjuYang, 💯 All CI checkers are successfully verified. Thanks.

@EunjuYang
Copy link
Contributor Author

Overall, It is ok but it might need further discussion.

I reflected the off-line discussion in
68ec281. Thanks :)

/** loraB: (lora_rank, out_dim) */
TensorDim loraB_dim(
1, is_nchw ? 1 : unit, is_nchw ? lora_rank : 1,
is_nchw ? unit : in_dim.channel(),
Copy link
Contributor

Choose a reason for hiding this comment

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

so there's no use of lora_rank in the channels last case for B?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It should be fixed! Thanks!!:)

This commit includes implementation of lora only for the FC layer, which means it is not the generalized version. It is required to be written as a seperate class in order to remove code duplicates for other layers

Signed-off-by: Eunju Yang <[email protected]>
This commit updates TfLite node exporter of fully conntected layer. It adds new property (LoraRank) as additional input property of fullyconnected layer

Signed-off-by: Eunju Yang <[email protected]>
- update type of LoraRank property : Property<int> -> PositiveIntegerProperty
- fix typo dot_batched_deriv_wrt_1 -> dot_deriv_wrt_1
- update code with add -> add_i
- apply clang-format

Signed-off-by: Eunju Yang <[email protected]>
- remove `forwarding_lora()` function
- update forwarding path with LoRA option
	- First, compute the forwarding logits of base weight (W) and lora weight (A @ B) respectively.
	- then merge the logits to return
	- [update] (W + A @ B)x -> Wx + (A @ B)x
- update `calcDerivative` to reflect the changes in forwarding operation
	- implicit update of calcDerivative is updated.

**Self-evaluation:**
1. Build test: [X]Passed [ ]Failed [ ]Skipped
2. Run test:   [X]Passed [ ]Failed [ ]Skipped

Signed-off-by: Eunju Yang <[email protected]>
- Fix typo in the code
- edit comments to to add some explanations

Signed-off-by: Eunju Yang <[email protected]>
- apply clang format to
	- nntrainer/tensor/tensor_v2.cpp
	- nntrainer/utils/node_exporter.cpp

Signed-off-by: Eunju Yang <[email protected]>
- remove a redundant and incorrect block comment in
`nntrainer/layers/fc_layer.cpp`

Signed-off-by: Eunju Yang <[email protected]>
- clang-format re-apply to pass static checker
- `fc_layer.cpp`

Signed-off-by: Eunju Yang <[email protected]>
Copy link
Member

@DonghakPark DonghakPark left a comment

Choose a reason for hiding this comment

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

LGTM!
i will fix FC Layer can support export to tflite format later

Copy link
Collaborator

@taos-ci taos-ci left a comment

Choose a reason for hiding this comment

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

@EunjuYang, 💯 All CI checkers are successfully verified. Thanks.

- updates the LoRA computation (applying Inception-LoRA)
- compute with LoRA vectors without matrix construction
- revise `forwarding()`
- revise `calcGradient()`
- revise `calcDerivative()`

Self evaluation:
	Build test: [X]Passed [ ]Failed [ ]Skipped
	Run test: [X]Passed [ ]Failed [ ]Skipped

Signed-off-by: Eunju Yang <[email protected]>
Copy link
Collaborator

@taos-ci taos-ci left a comment

Choose a reason for hiding this comment

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

@EunjuYang, 💯 All CI checkers are successfully verified. Thanks.

Copy link
Member

@SeoHyungjun SeoHyungjun 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
Collaborator

@jijoongmoon jijoongmoon left a comment

Choose a reason for hiding this comment

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

LGTM

@jijoongmoon jijoongmoon merged commit b581db6 into nnstreamer:main Apr 4, 2024
31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants