diff --git a/INFERENCE_GUIDE.md b/INFERENCE_GUIDE.md index 2a4ddff..b0bf02d 100644 --- a/INFERENCE_GUIDE.md +++ b/INFERENCE_GUIDE.md @@ -1,10 +1,13 @@ # Boogu Inference Guide -This document describes the current Boogu inference entry point for -text-to-image (T2I) generation and text/image-to-image (TI2I) editing: +This document describes the Boogu inference entry points: + +- `inference.py` for Base/Edit models (T2I and TI2I) +- `inference_turbo.py` for Turbo/Edit-Turbo models ```bash inference.py +inference_turbo.py ``` Many ready-to-run examples are available in: @@ -21,6 +24,19 @@ the built-in instruction reasoner / rewriter. For most users, the fastest way to start is to copy one of these scripts and adjust only the model path, prompt, input image paths, device settings, and output name. +Minimal Turbo example: + +```bash +export device="cuda:0" + +python inference_turbo.py \ + --pretrained_pipeline_name_or_path "models/Boogu-Image-0.1-Turbo" \ + --instruction "A scenic mountain landscape in warm golden light" \ + --height 1024 --width 1024 \ + --output_image_path "outputs/test_turbo/out_1.png" \ + --device "$device" +``` + Most demo scripts also set: ```bash diff --git a/README.md b/README.md index 7eb3c67..f808a78 100644 --- a/README.md +++ b/README.md @@ -143,7 +143,7 @@ conda create -y -n boogu python=3.10 conda activate boogu # Instal necessary dependencies # PyTorch up to 2.11.0 with CUDA up to 12.8 is supported -# Check `requirements/_.txt` +# Check `requirements/-.txt`, for example `requirements/torch2.7-cu126.txt` pip install -r requirements/torch2.7-cu126.txt pip install -e . python utils/get_flash_attn.py @@ -153,7 +153,9 @@ or ```bash bash quick_start.sh -conda activate boogu +# quick_start.sh may create boogu1/boogu2... if boogu already exists +# Use the exact command printed at the end of quick_start.sh +conda activate ``` ### Download Checkpoints @@ -183,7 +185,7 @@ models/ └── vae ``` -Then point inference to the local path via `--model models/Boogu-Image-0.1-Base`. +Then point inference to the local path via `--pretrained_pipeline_name_or_path models/Boogu-Image-0.1-Base`. ### Flash Attention diff --git a/README_CN.md b/README_CN.md index 9d4e457..62ce8b7 100644 --- a/README_CN.md +++ b/README_CN.md @@ -148,7 +148,7 @@ conda create -y -n boogu python=3.10 conda activate boogu # 安装必要的依赖 # 支持 PyTorch 最高 2.11.0,CUDA 最高 12.8 -# 查看 `requirements/_.txt` +# 查看 `requirements/-.txt`,例如 `requirements/torch2.7-cu126.txt` pip install -r requirements/torch2.7-cu126.txt pip install -e . python utils/get_flash_attn.py @@ -158,7 +158,9 @@ python utils/get_flash_attn.py ```bash bash quick_start.sh -conda activate boogu +# 如果 boogu 已存在,quick_start.sh 可能自动创建 boogu1/boogu2... +# 请使用 quick_start.sh 结束时打印出的激活命令 +conda activate ``` ### 下载模型权重 @@ -172,6 +174,7 @@ pip install -U "huggingface_hub[cli]" huggingface-cli download Boogu/Boogu-Image-0.1-Base --local-dir models/Boogu-Image-0.1-Base huggingface-cli download Boogu/Boogu-Image-0.1-Turbo --local-dir models/Boogu-Image-0.1-Turbo huggingface-cli download Boogu/Boogu-Image-0.1-Edit --local-dir models/Boogu-Image-0.1-Edit +huggingface-cli download Boogu/Boogu-Image-0.1-Edit-Turbo --local-dir models/Boogu-Image-0.1-Edit-Turbo ``` 下载后的目录结构示例: @@ -187,7 +190,7 @@ models/ └── vae ``` -然后通过 `--model models/Boogu-Image-0.1-Base` 指向本地路径进行推理。 +然后通过 `--pretrained_pipeline_name_or_path models/Boogu-Image-0.1-Base` 指向本地路径进行推理。 ### Flash Attention diff --git a/boogu/pipelines/boogu/pipeline_boogu.py b/boogu/pipelines/boogu/pipeline_boogu.py index bc106e4..89e4a2a 100644 --- a/boogu/pipelines/boogu/pipeline_boogu.py +++ b/boogu/pipelines/boogu/pipeline_boogu.py @@ -2078,7 +2078,7 @@ def _polish_instructions_with_remote_rewriter( ori_text: Union[str, List[str]], input_image_paths: Optional[Union[List[List[str]], List[str]]] = None, dashscope_base_http_api_url: str = "https://dashscope.aliyuncs.com/api/v1", - dashscope_api_key: str = "sk-xxxxxxxxxxxxxxxxxxxxxxxxxx", + dashscope_api_key: Optional[str] = None, remote_model: str = "qwen-vl-max-latest", MAX_TRIES: int = 3, ) -> List[str]: @@ -2152,7 +2152,7 @@ def _rewrite_text_instruction( use_dashscope_remote_rewriting: bool = False, dashscope_remote_rewriting_model: str = "qwen-vl-max-latest", dashscope_base_http_api_url: str = "https://dashscope.aliyuncs.com/api/v1", - dashscope_api_key: str = "sk-xxxxxxxxxxxxxxxxxxxxxxxxxx", + dashscope_api_key: Optional[str] = None, ): max_images_per_sample = 0 @@ -2287,7 +2287,7 @@ def encode_instruction( use_dashscope_remote_rewriting: bool = False, dashscope_remote_rewriting_model: str = "qwen-vl-max-latest", dashscope_base_http_api_url: str = "https://dashscope.aliyuncs.com/api/v1", - dashscope_api_key: str = "sk-xxxxxxxxxxxxxxxxxxxxxxxxxx", + dashscope_api_key: Optional[str] = None, system_prompt_follows_task_type: bool = False, task_type: str = "ti2i", ) -> Tuple[torch.Tensor, torch.Tensor, torch.Tensor, torch.Tensor]: @@ -2695,7 +2695,7 @@ def __call__( use_dashscope_remote_rewriting: bool = False, dashscope_remote_rewriting_model: str = "qwen-vl-max-latest", dashscope_base_http_api_url: str = "https://dashscope.aliyuncs.com/api/v1", - dashscope_api_key: str = "sk-xxxxxxxxxxxxxxxxxxxxxxxxxx", + dashscope_api_key: Optional[str] = None, system_prompt_follows_task_type: bool = False, ### Momentum Config use_boosted_orthogonal_guidance: bool = False, diff --git a/boogu/schedulers/scheduling_flow_match_euler_discrete_time_shifting.py b/boogu/schedulers/scheduling_flow_match_euler_discrete_time_shifting.py index c7b6b0a..45f2ac2 100644 --- a/boogu/schedulers/scheduling_flow_match_euler_discrete_time_shifting.py +++ b/boogu/schedulers/scheduling_flow_match_euler_discrete_time_shifting.py @@ -234,20 +234,9 @@ def set_timesteps( timesteps = t_arr - # ######################debug############################ - # print(f">> time_shift_version: {self.config.time_shift_version}") - # print(f">> timesteps: {timesteps}") - # print(f">> self.time_shift_v2_scaling_factor: {self.time_shift_v2_scaling_factor}") - # ####################################################### - timesteps = torch.from_numpy(timesteps).to(dtype=torch.float32, device=device) _timesteps = torch.cat([timesteps, torch.ones(1, device=timesteps.device)]) - # ######################debug############################ - # print(f">> len _timesteps: {len(_timesteps)}") - # print(f">> _timesteps: {_timesteps}") - # ####################################################### - self.timesteps = timesteps self._timesteps = _timesteps self._step_index = None diff --git a/demo_scripts/demo_ti2i_remote_reasoning.sh b/demo_scripts/demo_ti2i_remote_reasoning.sh index c6df7a5..e5750dc 100644 --- a/demo_scripts/demo_ti2i_remote_reasoning.sh +++ b/demo_scripts/demo_ti2i_remote_reasoning.sh @@ -44,7 +44,15 @@ use_rewrite_text_instruction=True use_dashscope_remote_rewriting=True dashscope_remote_rewriting_model="qwen-vl-max-latest" dashscope_base_http_api_url="https://dashscope.aliyuncs.com/api/v1" -dashscope_api_key="sk-xxxxxxxxxxxxxxxxxxxxxxxxxx" +# Read the DashScope API key from the environment instead of hardcoding a placeholder. +# Export it before running this script, e.g.: +# export DASHSCOPE_API_KEY="sk-your-real-key-here" +if [ -z "${DASHSCOPE_API_KEY:-}" ]; then + echo "Error: DASHSCOPE_API_KEY is not set. Export it before running this script, e.g.:" >&2 + echo " export DASHSCOPE_API_KEY=\"sk-your-real-key-here\"" >&2 + exit 1 +fi +dashscope_api_key="${DASHSCOPE_API_KEY}" save_rewritten_instruction=True save_rewritten_instruction_path="outputs/${experiment_name}/${case_name}_rewritten_instruction.json" diff --git a/inference.py b/inference.py index f18b5b9..09eeda7 100644 --- a/inference.py +++ b/inference.py @@ -448,8 +448,8 @@ def parse_args() -> argparse.Namespace: parser.add_argument( "--dashscope_api_key", type=str, - default="sk-xxxxxxxxxxxxxxxxxxxxxxxxxx", - help="The api key for dashscope. Only takes effect when `use_rewrite_text_instruction` is True and `use_dashscope_remote_rewriting` is True.", + default=None, + help="The api key for dashscope. Only takes effect when `use_rewrite_text_instruction` is True and `use_dashscope_remote_rewriting` is True. Must be set to a valid key when `use_dashscope_remote_rewriting=True`; the pipeline will assert and refuse to run with the placeholder value.", ) parser.add_argument( diff --git a/inference_turbo.py b/inference_turbo.py index 509c651..640bada 100644 --- a/inference_turbo.py +++ b/inference_turbo.py @@ -448,8 +448,8 @@ def parse_args() -> argparse.Namespace: parser.add_argument( "--dashscope_api_key", type=str, - default="sk-xxxxxxxxxxxxxxxxxxxxxxxxxx", - help="The api key for dashscope. Only takes effect when `use_rewrite_text_instruction` is True and `use_dashscope_remote_rewriting` is True.", + default=None, + help="The api key for dashscope. Only takes effect when `use_rewrite_text_instruction` is True and `use_dashscope_remote_rewriting` is True. Must be set to a valid key when `use_dashscope_remote_rewriting=True`; the pipeline will assert and refuse to run with the placeholder value.", ) parser.add_argument(