Skip to content
Open
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
20 changes: 18 additions & 2 deletions INFERENCE_GUIDE.md
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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
Expand Down
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/<torch>_<cuda>.txt`
# Check `requirements/<torch>-<cuda>.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
Expand All @@ -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 <env_name_printed_by_quick_start>
```

### Download Checkpoints
Expand Down Expand Up @@ -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

Expand Down
9 changes: 6 additions & 3 deletions README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ conda create -y -n boogu python=3.10
conda activate boogu
# 安装必要的依赖
# 支持 PyTorch 最高 2.11.0,CUDA 最高 12.8
# 查看 `requirements/<torch>_<cuda>.txt`
# 查看 `requirements/<torch>-<cuda>.txt`,例如 `requirements/torch2.7-cu126.txt`
pip install -r requirements/torch2.7-cu126.txt
pip install -e .
python utils/get_flash_attn.py
Expand All @@ -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 <quick_start.sh输出的环境名>
```

### 下载模型权重
Expand All @@ -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
```

下载后的目录结构示例:
Expand All @@ -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

Expand Down
8 changes: 4 additions & 4 deletions boogu/pipelines/boogu/pipeline_boogu.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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]:
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 9 additions & 1 deletion demo_scripts/demo_ti2i_remote_reasoning.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions inference_turbo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down