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

fix the tutorial of llama to support specify paths #406

Merged
merged 2 commits into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions examples/python/ml/flax_llama7b/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,13 @@ This example demonstrates how to use SPU to run secure inference on a pre-traine
Download trained LLaMA-B[PyTroch-Version] from [Hugging Face](https://huggingface.co/openlm-research/open_llama_7b)
, and convert it to Flax.msgpack as:

```sh
python3 -m EasyLM.scripts.convert_checkpoint --load_checkpoint='params::path-to-LLaMA-7B[Pytroch-Version]' --output_file='path-to-LLaMMA-7B.msgpack' --streaming=False
```sh
cd path_to_EasyLM/EasyLM/models/llama
python convert_hf_to_easylm.py \
--checkpoint_dir path-to-flax-llama7b-dir \
--output_file path-to-flax-llama7b-EasyLM.msgpack \
--model_size 7b \
--streaming
```

3. Launch SPU backend runtime
Expand Down
10 changes: 5 additions & 5 deletions examples/python/ml/flax_llama7b_split/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ This example demonstrates how to use SPU to run secure inference on a pre-traine
```sh
cd path_to_EasyLM/EasyLM/models/llama
python convert_hf_to_easylm.py \
--checkpoint_dir path_to_llama_weights \
--output_file path_to_outputfile \
--checkpoint_dir path-to-flax-llama7b-dir \
--output_file path-to-flax-llama7b-EasyLM.msgpack \
--model_size 7b \
--streaming
```
Expand All @@ -73,20 +73,20 @@ This example demonstrates how to use SPU to run secure inference on a pre-traine

```sh
cd examples/python/utils
python nodectl.py --config `pwd`/examples/python/ml/flax_llama7b_split/3pc.json up
python nodectl.py --config ../ml/flax_llama7b_split/3pc.json up
```

4. Run `flax_llama7b_split` example

```sh
bazel run -c opt //examples/python/ml/flax_llama7b_split -- --config `pwd`/examples/python/ml/flax_llama7b_split/3pc.json
bazel run -c opt //examples/python/ml/flax_llama7b_split -- --model_path path-to-flax-llama7b-EasyLM.msgpack --tokenizer_path path-to-flax-llama7b-dir --config `pwd`/examples/python/ml/flax_llama7b_split/3pc.json
```

or(recommended)

```sh
cd examples/python/ml/flax_llama7b_split
python flax_llama7b_split.py --config `pwd`/examples/python/ml/flax_llama7b_split/3pc.json
python flax_llama7b_split.py --model_path path-to-flax-llama7b-EasyLM.msgpack --tokenizer_path path-to-flax-llama7b-dir --config ./3pc.json
gystar marked this conversation as resolved.
Show resolved Hide resolved
```

and you can get the following results from our example:
Expand Down
11 changes: 8 additions & 3 deletions examples/python/ml/flax_llama7b_split/flax_llama7b_split.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@
parser.add_argument(
"-c", "--config", default="examples/python/ml/flax_llama_split/3pc.json"
)
parser.add_argument(
"-m", "--model_path", help="please input the path-to-flax-llama7b-EasyLM.msgpack"
)
parser.add_argument(
"-t", "--tokenizer_path", help="please input the path-to-flax-llama7b-dir"
)
args = parser.parse_args()

with open(args.config, 'r') as file:
Expand All @@ -63,9 +69,8 @@

# model_path = 'path-to-flax-llama7b'

model_path = "params::path-to-flax-llama7b-checkpoint"
tokenizer_path = "path-to-flax-llama7b"
tokenizer = LlamaTokenizer.from_pretrained(tokenizer_path)
model_path = f"params::{args.model_path}"
tokenizer = LlamaTokenizer.from_pretrained(args.tokenizer_path)
tokenizer.pad_token_id = tokenizer.eos_token_id
config = LLaMAConfig()
# pretrained_model = FlaxLLaMAForCausalLM.from_pretrained(model_path, config=config)
Expand Down
Loading