-
Notifications
You must be signed in to change notification settings - Fork 32
Rmsnorm #136
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
Merged
Merged
Rmsnorm #136
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
9b74876
test 1
lee2716 5d499d4
test
lee2716 3499a64
Merge branch 'pulp-platform:devel' into rmsnorm
lee2716 30cfabb
add pow2_fp16,pow2_fp32,sqrt_fp16,sqrt_fp32, rmsnorm_fp32, rmsnorm_fp…
lee2716 360519c
Remove FP16 tests due to lack of native support
lee2716 fee8470
Removing FP16 tests in CI
lee2716 8f90620
Refactor Pow for float support, remove FP16, and cleanup parsers
lee2716 4834c2a
recover the teseRMSNorm and updated 128*128 version of testFloatRMSNorm
lee2716 e1785a8
Fix: Address review comments (dynamic types, vector Pow test, CI upda…
lee2716 8ecf929
remove the testFloatPow, which has been renamed to testFloatPowScalar
lee2716 2e857bd
add change log
lee2716 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,6 +24,8 @@ package-lock.json | |
| .mypy_cache | ||
| node_modules | ||
|
|
||
| .venv/* | ||
|
|
||
| compile_commands.json | ||
|
|
||
| docs/_autosummary | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diaconuccalin marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| # SPDX-FileCopyrightText: 2025 ETH Zurich and University of Bologna | ||
| # | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| from typing import Dict, List, Tuple | ||
|
|
||
| import numpy as np | ||
|
|
||
| from Deeploy.DeeployTypes import NetworkContext, NodeTemplate, OperatorRepresentation | ||
|
|
||
|
|
||
| class _PowTemplate(NodeTemplate): | ||
|
|
||
| def alignToContext(self, ctxt: NetworkContext, | ||
| operatorRepresentation: OperatorRepresentation) -> Tuple[NetworkContext, Dict, List[str]]: | ||
| # Get input and output tensors | ||
| data_in = ctxt.lookup(operatorRepresentation['data_in']) | ||
| exponent = ctxt.lookup(operatorRepresentation['exponent']) | ||
| data_out = ctxt.lookup(operatorRepresentation['data_out']) | ||
|
|
||
| # Get data type (fp32) | ||
diaconuccalin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| data_type = data_in._type.typeName | ||
| operatorRepresentation['data_type'] = data_type | ||
|
|
||
| # Get type width dynamically (e.g., 32, 64) | ||
| type_width = data_in._type.referencedType.typeWidth | ||
| operatorRepresentation['type_width'] = type_width | ||
|
|
||
| # Calculate size | ||
| input_size = int(np.prod(data_in.shape)) | ||
| exponent_size = int(np.prod(exponent.shape)) | ||
| operatorRepresentation['size'] = input_size | ||
|
|
||
| # Check if exponent is scalar (broadcasting) | ||
| if exponent_size == 1: | ||
| operatorRepresentation['is_scalar'] = True | ||
| # Get the full variable name with prefix | ||
| exponent_name = operatorRepresentation['exponent'] | ||
| operatorRepresentation['exponent_scalar'] = f"DeeployNetwork_{exponent_name}[0]" | ||
| else: | ||
| # Since currently the kernel only supports equally sized base-exponent data, | ||
| # for non-scalar, let's add a size check here (length of data_in should be equal to exponent length). | ||
| if input_size != exponent_size: | ||
| raise ValueError(f"Pow operator mismatch: input size ({input_size}) " | ||
| f"must equal exponent size ({exponent_size}) for non-scalar exponents.") | ||
|
|
||
| operatorRepresentation['is_scalar'] = False | ||
diaconuccalin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| operatorRepresentation['exponent_scalar'] = "NULL" | ||
|
|
||
| return ctxt, operatorRepresentation, [] | ||
|
|
||
|
|
||
| referenceTemplate = _PowTemplate(""" | ||
| // Pow (Name: ${nodeName}, Op: ${nodeOp}) | ||
| % if is_scalar: | ||
diaconuccalin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| Pow_fp${type_width}_scalar_fp${type_width}(${data_in}, ${exponent_scalar}, ${data_out}, ${size}); | ||
| % else: | ||
| Pow_fp${type_width}_fp${type_width}_fp${type_width}(${data_in}, ${exponent}, ${data_out}, ${size}); | ||
| % endif | ||
| """) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| # SPDX-FileCopyrightText: 2025 ETH Zurich and University of Bologna | ||
| # | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| from typing import Dict, List, Tuple | ||
|
|
||
| import numpy as np | ||
|
|
||
| from Deeploy.DeeployTypes import NetworkContext, NodeTemplate, OperatorRepresentation | ||
|
|
||
|
|
||
| class _SqrtTemplate(NodeTemplate): | ||
|
|
||
| def alignToContext(self, ctxt: NetworkContext, | ||
| operatorRepresentation: OperatorRepresentation) -> Tuple[NetworkContext, Dict, List[str]]: | ||
| # Get input and output tensors | ||
| data_in = ctxt.lookup(operatorRepresentation['data_in']) | ||
| data_out = ctxt.lookup(operatorRepresentation['data_out']) | ||
|
|
||
| # Get data type (fp32) | ||
| data_type = data_in._type.typeName | ||
| operatorRepresentation['data_type'] = data_type | ||
|
|
||
| type_width = data_in._type.referencedType.typeWidth | ||
| operatorRepresentation['type_width'] = type_width | ||
|
|
||
| # Calculate size | ||
| operatorRepresentation['size'] = int(np.prod(data_in.shape)) | ||
|
|
||
| return ctxt, operatorRepresentation, [] | ||
|
|
||
|
|
||
| referenceTemplate = _SqrtTemplate(""" | ||
| // Sqrt (Name: ${nodeName}, Op: ${nodeOp}) | ||
| Sqrt_fp${type_width}_fp${type_width}(${data_in}, ${data_out}, ${size}); | ||
| """) |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| deeploy_test_generator:· | ||
| 3 | ||
| data_in | ||
| exponentdata_outPow_Vector_Test"Powtest_float_pow_vectorZ! | ||
| data_in | ||
| Z" | ||
| exponent | ||
| b" | ||
| data_out | ||
| B |
Binary file not shown.
diaconuccalin marked this conversation as resolved.
Show resolved
Hide resolved
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| /* | ||
| * SPDX-FileCopyrightText: 2025 ETH Zurich and University of Bologna | ||
| * | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| /* | ||
| * This file implements the element-wise binary power operation. | ||
| */ | ||
|
|
||
| #ifndef __DEEPLOY_MATH_POW_KERNEL_HEADER_ | ||
| #define __DEEPLOY_MATH_POW_KERNEL_HEADER_ | ||
|
|
||
| #include "DeeployBasicMath.h" | ||
|
|
||
| void Pow_fp32_fp32_fp32(const float32_t *__restrict__ data_in, | ||
| const float32_t *__restrict__ exponent, | ||
| float32_t *__restrict__ data_out, int32_t size); | ||
|
|
||
| void Pow_fp32_scalar_fp32(const float32_t *__restrict__ data_in, | ||
| float32_t exponent, float32_t *__restrict__ data_out, | ||
| int32_t size); | ||
|
|
||
| #endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| /* | ||
| * SPDX-FileCopyrightText: 2020 ETH Zurich and University of Bologna | ||
| * | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| #ifndef __DEEPLOY_BASIC_MATH_SQRT_KERNEL_HEADER_ | ||
| #define __DEEPLOY_BASIC_MATH_SQRT_KERNEL_HEADER_ | ||
|
|
||
| #include "DeeployBasicMath.h" | ||
|
|
||
| /* | ||
| * Square root operation - computes sqrt for each element | ||
| */ | ||
|
|
||
| /******************************************************************************/ | ||
| /* Sqrt */ | ||
| /******************************************************************************/ | ||
|
|
||
| void Sqrt_fp32_fp32(float32_t *data_in, float32_t *data_out, int32_t size); | ||
|
|
||
| #endif //__DEEPLOY_BASIC_MATH_SQRT_KERNEL_HEADER_ |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.