-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'inference' of https://github.com/flexflow/FlexFlow into…
… update_legion
- Loading branch information
Showing
63 changed files
with
2,956 additions
and
24 deletions.
There are no files selected for viewing
This file contains 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 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 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 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
Submodule tokenizers-cpp
updated
19 files
+3 −0 | .gitmodules | |
+28 −4 | CMakeLists.txt | |
+0 −1 | example/CMakeLists.txt | |
+5 −1 | example/build_and_run.sh | |
+69 −18 | example/example.cc | |
+17 −2 | include/tokenizers_c.h | |
+38 −0 | include/tokenizers_cpp.h | |
+1 −0 | msgpack | |
+1 −1 | rust/Cargo.toml | |
+100 −16 | rust/src/lib.rs | |
+64 −10 | src/huggingface_tokenizer.cc | |
+143 −0 | src/rwkv_world_tokenizer.cc | |
+33 −0 | src/rwkv_world_tokenizer.h | |
+20 −1 | src/sentencepiece_tokenizer.cc | |
+1 −1 | web/build.sh | |
+2 −2 | web/package.json | |
+31 −10 | web/src/tokenizers.ts | |
+3 −1 | web/src/tokenizers_binding.cc | |
+22 −1 | web/tests/src/index.ts |
This file contains 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 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 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,45 @@ | ||
# The basis for this test of the 'add' operation is generated by ChatGPT using the manually created conv2d.py as a template. | ||
|
||
|
||
import flexflow.core | ||
import numpy as np | ||
from flexflow.core import * | ||
|
||
def test_add(ffconfig, input_arr1: np.ndarray, input_arr2: np.ndarray) -> flexflow.core.Tensor: | ||
ffmodel = FFModel(ffconfig) | ||
|
||
input_tensor1 = ffmodel.create_tensor(input_arr1.shape, DataType.DT_FLOAT) | ||
input_tensor2 = ffmodel.create_tensor(input_arr2.shape, DataType.DT_FLOAT) | ||
|
||
out = ffmodel.add(input_tensor1, input_tensor2) | ||
|
||
ffoptimizer = SGDOptimizer(ffmodel, 0.001) | ||
ffmodel.optimizer = ffoptimizer | ||
ffmodel.compile( | ||
loss_type=LossType.LOSS_SPARSE_CATEGORICAL_CROSSENTROPY, | ||
metrics=[MetricsType.METRICS_ACCURACY, MetricsType.METRICS_SPARSE_CATEGORICAL_CROSSENTROPY]) | ||
dataloader_input1 = ffmodel.create_data_loader(input_tensor1, input_arr1) | ||
dataloader_input2 = ffmodel.create_data_loader(input_tensor2, input_arr2) | ||
|
||
ffmodel.init_layers() | ||
|
||
dataloader_input1.reset() | ||
dataloader_input1.next_batch(ffmodel) | ||
|
||
dataloader_input2.reset() | ||
dataloader_input2.next_batch(ffmodel) | ||
|
||
ffmodel.forward() | ||
|
||
out.inline_map(ffmodel, ffconfig) | ||
return out.get_array(ffmodel, ffconfig) | ||
|
||
|
||
if __name__ == '__main__': | ||
init_flexflow_runtime() | ||
ffconfig = FFConfig() | ||
|
||
input1 = np.random.randn(ffconfig.batch_size, 5, 10, 10).astype(np.float32) | ||
input2 = np.random.randn(ffconfig.batch_size, 5, 10, 10).astype(np.float32) | ||
|
||
_ = test_add(ffconfig, input1, input2) |
78 changes: 78 additions & 0 deletions
78
examples/python/native/ops/add_bias_residual_layer_norm.py
This file contains 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,78 @@ | ||
from typing import List | ||
|
||
import flexflow.core | ||
import numpy as np | ||
from flexflow.core import * | ||
|
||
|
||
def test_add_bias_residual_layer_norm(ffconfig, input_arr: np.ndarray, residual_arr: np.ndarray, axes: List[int], elementwise_affine: bool = True, eps: float = 1e-5, use_bias: bool = True, name=None): | ||
ffmodel = FFModel(ffconfig) | ||
|
||
input_tensor = ffmodel.create_tensor(input_arr.shape, DataType.DT_FLOAT) | ||
residual_tensor = ffmodel.create_tensor(residual_arr.shape, DataType.DT_FLOAT) | ||
|
||
output_tensor, layer_norm_output = ffmodel.add_bias_residual_layer_norm( | ||
input_tensor, | ||
residual_tensor, | ||
axes=axes, | ||
elementwise_affine=elementwise_affine, | ||
eps=eps, | ||
use_bias=use_bias, | ||
name="add_bias_residual_layer_norm_layer" | ||
) | ||
|
||
ffoptimizer = SGDOptimizer(ffmodel, 0.001) | ||
ffmodel.optimizer = ffoptimizer | ||
ffmodel.compile( | ||
loss_type=LossType.LOSS_SPARSE_CATEGORICAL_CROSSENTROPY, | ||
metrics=[MetricsType.METRICS_ACCURACY, MetricsType.METRICS_SPARSE_CATEGORICAL_CROSSENTROPY] | ||
) | ||
|
||
dataloader_input = ffmodel.create_data_loader(input_tensor, input_arr) | ||
dataloader_residual = ffmodel.create_data_loader(residual_tensor, residual_arr) | ||
|
||
ffmodel.init_layers() | ||
|
||
dataloader_input.reset() | ||
dataloader_residual.reset() | ||
|
||
dataloader_input.next_batch(ffmodel) | ||
dataloader_residual.next_batch(ffmodel) | ||
|
||
ffmodel.forward() | ||
|
||
output_tensor.inline_map(ffmodel, ffconfig) | ||
layer_norm_output.inline_map(ffmodel, ffconfig) | ||
output_result = output_tensor.get_array(ffmodel, ffconfig) | ||
layer_norm_result = layer_norm_output.get_array(ffmodel, ffconfig) | ||
|
||
return output_result, layer_norm_result | ||
|
||
|
||
if __name__ == '__main__': | ||
init_flexflow_runtime() | ||
ffconfig = FFConfig() | ||
|
||
input_data = np.random.randn(ffconfig.batch_size, 5, 10, 10).astype(np.float32) | ||
residual_data = np.random.randn(ffconfig.batch_size, 5, 10, 10).astype(np.float32) | ||
|
||
axes_to_normalize = [1, 2] # Example axes to normalize | ||
|
||
output_result, layer_norm_result = test_add_bias_residual_layer_norm( | ||
ffconfig, | ||
input_data, | ||
residual_data, | ||
axes=axes_to_normalize, | ||
elementwise_affine=True, | ||
eps=1e-5, | ||
use_bias=True | ||
) | ||
|
||
print("Input Array:") | ||
print(input_data) | ||
print("\nResidual Array:") | ||
print(residual_data) | ||
print(f"\nOutput Array after applying add_bias_residual_layer_norm along axes {axes_to_normalize}:") | ||
print(output_result) | ||
print("\nLayer Norm Result:") | ||
print(layer_norm_result) |
This file contains 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,61 @@ | ||
import flexflow.core | ||
import numpy as np | ||
from flexflow.core import * | ||
|
||
|
||
def test_arg_top_k(ffconfig, input_arr: np.ndarray, k: int, sorted: bool, speculative_decoding: bool, name=None): | ||
ffmodel = FFModel(ffconfig) | ||
|
||
input_tensor = ffmodel.create_tensor(input_arr.shape, DataType.DT_FLOAT) | ||
|
||
arg_top_k_output = ffmodel.arg_top_k( | ||
input_tensor, | ||
k, | ||
sorted, | ||
speculative_decoding, | ||
name="arg_top_k_layer", | ||
) | ||
|
||
ffoptimizer = SGDOptimizer(ffmodel, 0.001) | ||
ffmodel.optimizer = ffoptimizer | ||
ffmodel.compile( | ||
loss_type=LossType.LOSS_MEAN_SQUARED_ERROR, | ||
metrics=[MetricsType.METRICS_MEAN_SQUARED_ERROR], | ||
) | ||
|
||
dataloader_input = ffmodel.create_data_loader(input_tensor, input_arr) | ||
|
||
ffmodel.init_layers() | ||
|
||
dataloader_input.reset() | ||
dataloader_input.next_batch(ffmodel) | ||
|
||
ffmodel.forward() | ||
|
||
arg_top_k_output.inline_map(ffmodel, ffconfig) | ||
output_result = arg_top_k_output.get_array(ffmodel, ffconfig) | ||
|
||
return output_result | ||
|
||
|
||
if __name__ == '__main__': | ||
init_flexflow_runtime() | ||
ffconfig = FFConfig() | ||
|
||
input_data = np.random.randn(ffconfig.batch_size, 10).astype(np.float32) | ||
k_value = 5 | ||
sorted_value = True | ||
speculative_decoding_value = False # Example value for speculative_decoding | ||
|
||
output_result = test_arg_top_k( | ||
ffconfig, | ||
input_data, | ||
k=k_value, | ||
sorted=sorted_value, | ||
speculative_decoding=speculative_decoding_value, | ||
) | ||
|
||
print("Input Array:") | ||
print(input_data) | ||
print("\nOutput Array after applying arg_top_k:") | ||
print(output_result) |
Oops, something went wrong.