-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[PFunc] Add Simple Python Native Function Support (#9)
* init * fix launch part * init native func & fix requirement * rename placeholder to parameter for consistency with native function * add utils for serialization * add serve core support for native func * fix tests * remove rubbish * add executor and refactor graph traverse * fix e2e problem * pass e2e
- Loading branch information
Showing
66 changed files
with
2,298 additions
and
955 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#!/usr/bin/env bash | ||
# Copyright (c) 2023 by Microsoft Corporation. | ||
# Licensed under the MIT license. | ||
|
||
export TORCH_CUDA_ARCH_LIST=8.0 | ||
export CUDA_HOME=/root/cuda-12.1 | ||
export LD_LIBRARY_PATH=/root/cuda-12.1/lib64:$LD_LIBRARY_PATH | ||
|
||
export SIMULATE_NETWORK_LATENCY_PRT=1 # 0 off, 1 on | ||
export SIMULATE_NETWORK_LATENCY_FS=1 # 0 off, 1 on | ||
|
||
export HF_ENDPOINT="https://hf-mirror.com" | ||
|
||
# CUDA_LAUNCH_BLOCKING=1 |
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 |
---|---|---|
|
@@ -441,6 +441,9 @@ data | |
*.so | ||
|
||
# Test cache | ||
tests/*.png | ||
|
||
# Exclude pdf in assets | ||
!assets/*.pdf | ||
|
||
|
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,2 @@ | ||
# Contributing | ||
|
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
File renamed without changes.
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
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
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,32 @@ | ||
# Copyright (c) 2024 by Microsoft Corporation. | ||
# Author: Chaofan Lin ([email protected]) | ||
|
||
from parrot import P | ||
|
||
vm = P.VirtualMachine( | ||
core_http_addr="http://localhost:9000", | ||
mode="debug", | ||
) | ||
|
||
|
||
@P.semantic_function() | ||
def tell_me_a_joke(topic: P.Input, joke: P.Output): | ||
"""Tell the me a joke about {{topic}}: {{joke}}.""" | ||
|
||
|
||
@P.native_function() | ||
def format_joke(joke: P.Input, formatted_joke: P.Output): | ||
ret = ( | ||
"Here is the joke for you\n---\n" + joke | ||
) # Directly use string built-in methods | ||
formatted_joke.set(ret) # Use `set` to assign value to output | ||
|
||
|
||
def main(): # Orchestrator function | ||
joke = tell_me_a_joke(topic="chicken") | ||
joke1 = format_joke(joke) | ||
joke_str = joke1.get() | ||
print(joke_str) | ||
|
||
|
||
vm.run(main) |
Oops, something went wrong.