-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
zhaoting
committed
Feb 17, 2025
1 parent
f73a600
commit feec90d
Showing
35 changed files
with
4,349 additions
and
326 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
import argparse | ||
import pathlib | ||
import shutil | ||
|
||
import numpy as np | ||
import mindspore as ms | ||
|
||
from mindone import diffusers | ||
|
||
|
||
def parse_args() -> argparse.Namespace: | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument( | ||
"--pretrained_model_name_or_path", | ||
type=str, | ||
default="THUDM/CogVideoX1.5-5b", | ||
help="Path to pretrained model or model identifier from huggingface.co/models.", | ||
) | ||
parser.add_argument( | ||
"--prompt", | ||
type=str, | ||
default=None, | ||
help="prompt, if None, will set default prompt.", | ||
) | ||
parser.add_argument( | ||
"--transformer_ckpt_path", | ||
type=str, | ||
default=None, | ||
help="Path to the transformer checkpoint.", | ||
) | ||
parser.add_argument( | ||
"--height", | ||
type=int, | ||
default=1360, | ||
help="The height of the output video.", | ||
) | ||
parser.add_argument( | ||
"--width", | ||
type=int, | ||
default=768, | ||
help="The width of the output video.", | ||
) | ||
parser.add_argument( | ||
"--frame", | ||
type=int, | ||
default=77, | ||
help="The frame of the output video.", | ||
) | ||
parser.add_argument( | ||
"--npy_output_path", | ||
type=str, | ||
default=None, | ||
help="Path to save the inferred numpy array.", | ||
) | ||
parser.add_argument( | ||
"--video_output_path", | ||
type=str, | ||
default=None, | ||
help="Path to save the inferred video.", | ||
) | ||
return parser.parse_args() | ||
|
||
|
||
def infer(args: argparse.Namespace) -> None: | ||
ms.set_context(mode=ms.GRAPH_MODE, jit_config={"jit_level": "O1"}) | ||
pipe = diffusers.CogVideoXPipeline.from_pretrained( | ||
args.pretrained_model_name_or_path, mindspore_dtype=ms.bfloat16, use_safetensors=True | ||
) | ||
|
||
if args.transformer_ckpt_path is not None: | ||
ckpt = ms.load_checkpoint(args.transformer_ckpt_path) | ||
processed_ckpt = {name[12:]: value for name, value in ckpt.items()} # remove "transformer." prefix | ||
param_not_load, ckpt_not_load = ms.load_param_into_net(pipe.transformer, processed_ckpt) | ||
if param_not_load: | ||
raise RuntimeError(f"{param_not_load} was not loaded into net.") | ||
if ckpt_not_load: | ||
raise RuntimeError(f"{ckpt_not_load} was not loaded from checkpoint.") | ||
print("Successfully loaded transformer checkpoint.") | ||
|
||
pipe.vae.enable_tiling() | ||
pipe.vae.enable_slicing() | ||
prompt = "A panda, dressed in a small, red jacket and a tiny hat, sits on a wooden stool in a serene bamboo forest. The panda's fluffy paws strum a miniature acoustic guitar, producing soft, melodic tunes. Nearby, a few other pandas gather, watching curiously and some clapping in rhythm. Sunlight filters through the tall bamboo, casting a gentle glow on the scene. The panda's face is expressive, showing concentration and joy as it plays. The background includes a small, flowing stream and vibrant green foliage, enhancing the peaceful and magical atmosphere of this unique musical performance." | ||
prompt = prompt if args.prompt is None else args.prompt | ||
video = pipe(prompt=prompt, height=args.height, width=args.width, num_frames=args.frame)[0][0] | ||
|
||
if args.npy_output_path is not None: | ||
path = pathlib.Path(args.npy_output_path) | ||
if path.exists(): | ||
shutil.rmtree(path) | ||
path.mkdir() | ||
index_max_length = len(str(len(video))) | ||
for index, image in enumerate(video): | ||
np.save(path / f"image_{str(index).zfill(index_max_length)}", np.array(image)) | ||
print("Successfully saved the inferred numpy array.") | ||
|
||
if args.video_output_path is not None: | ||
diffusers.utils.export_to_video(video, args.video_output_path, fps=8) | ||
print("Successfully saved the inferred video.") | ||
|
||
|
||
if __name__ == "__main__": | ||
args = parse_args() | ||
infer(args) |
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
33 changes: 33 additions & 0 deletions
33
examples/diffusers/cogvideox_factory/tests/run_3d_causal_vae.sh
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,33 @@ | ||
#export ASCEND_RT_VISIBLE_DEVICES=0,1,2,3,4,5,6,7 | ||
# Num of NPUs for test | ||
export MS_DEV_RUNTIME_CONF="memory_statistics:True" | ||
# export MS_DEV_LAZY_FUSION_FLAGS="--opt_level=1" | ||
NUM_NPUS=4 | ||
# export DEVICE_ID=3 | ||
|
||
SCRIPT_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" | ||
PROJECT_DIR="$(dirname "${SCRIPT_DIR}")" | ||
EXAMPLE_DIR="$(dirname "${PROJECT_DIR}")" | ||
PACKAGE_DIR="$(dirname "${EXAMPLE_DIR}")" | ||
|
||
export PYTHONPATH="${PROJECT_DIR}:${PACKAGE_DIR}:${PYTHONPATH}" | ||
|
||
# Prepare launch cmd according to NUM_NPUS | ||
if [ "$NUM_NPUS" -eq 1 ]; then | ||
cpus=`cat /proc/cpuinfo| grep "processor"| wc -l` | ||
avg=`expr $cpus \/ 8` | ||
gap=`expr $avg \- 1` | ||
start=`expr $DEVICE_ID \* $avg` | ||
end=`expr $start \+ $gap` | ||
cmdopt=$start"-"$end | ||
LAUNCHER="taskset -c $cmdopt python" | ||
EXTRA_ARGS="" | ||
else | ||
LAUNCHER="msrun --bind_core=True --worker_num=$NUM_NPUS --local_worker_num=$NUM_NPUS --log_dir=log_test_vae --join True" | ||
fi | ||
|
||
echo "Start Running:" | ||
cmd="$LAUNCHER ${SCRIPT_DIR}/test_3d_causal_vae.py" | ||
echo "Running command: $cmd" | ||
eval $cmd | ||
echo "==============================================" |
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,9 @@ | ||
NUM_NPUS=4 | ||
SCRIPT_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" | ||
PROJECT_DIR="$(dirname "${SCRIPT_DIR}")" | ||
EXAMPLE_DIR="$(dirname "${PROJECT_DIR}")" | ||
PACKAGE_DIR="$(dirname "${EXAMPLE_DIR}")" | ||
|
||
export PYTHONPATH="${PROJECT_DIR}:${PACKAGE_DIR}:${PYTHONPATH}" | ||
|
||
msrun --master_port=2234 --worker_num=$NUM_NPUS --local_worker_num=$NUM_NPUS --bind_core=True --log_dir="./log_test_send_recv" --join True ${SCRIPT_DIR}/test_send_recv.py |
16 changes: 16 additions & 0 deletions
16
examples/diffusers/cogvideox_factory/tests/run_test_cogvideox_sequence_parallelism.sh
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,16 @@ | ||
#!/bin/sh | ||
export MS_DEV_RUNTIME_CONF="memory_statistics:True" | ||
#export MS_DEV_RUNTIME_CONF="memory_statistics:True,compile_statistics:True" | ||
#export ASCEND_RT_VISIBLE_DEVICES=2,3 | ||
NUM_NPUS=2 | ||
SCRIPT_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" | ||
PROJECT_DIR="$(dirname "${SCRIPT_DIR}")" | ||
EXAMPLE_DIR="$(dirname "${PROJECT_DIR}")" | ||
PACKAGE_DIR="$(dirname "${EXAMPLE_DIR}")" | ||
|
||
export PYTHONPATH="${PROJECT_DIR}:${PACKAGE_DIR}:${PYTHONPATH}" | ||
|
||
echo "Start Running:" | ||
msrun --master_port=1234 --worker_num=$NUM_NPUS --local_worker_num=$NUM_NPUS --bind_core=True --log_dir="./log_test_sp_graph" --join True ${SCRIPT_DIR}/test_cogvideox_sequence_parallelism.py | ||
echo "Done. Check the log at './log_test_sp_graph'." | ||
echo "==============================================" |
Oops, something went wrong.