Test ImageNet reconstruction. Args: model_path: Path to VTP HuggingFace model directory data_path: Path to ImageNet validation dataset output_path: Output directory for reconstructed images device: Device to use (ignored if use_ddp=True) batch_size: Batch
(
model_path: str,
data_path: str,
output_path: str = "reconstruction_output",
device: str = "cuda:0",
batch_size: int = 32,
precision: str = "bf16",
save_images: bool = True,
use_ddp: bool = False,
num_workers: int = 4,
max_samples: int = None,
)
| 189 | # ============================================================================ |
| 190 | |
| 191 | def test_reconstruction( |
| 192 | model_path: str, |
| 193 | data_path: str, |
| 194 | output_path: str = "reconstruction_output", |
| 195 | device: str = "cuda:0", |
| 196 | batch_size: int = 32, |
| 197 | precision: str = "bf16", |
| 198 | save_images: bool = True, |
| 199 | use_ddp: bool = False, |
| 200 | num_workers: int = 4, |
| 201 | max_samples: int = None, |
| 202 | ): |
| 203 | """Test ImageNet reconstruction. |
| 204 | |
| 205 | Args: |
| 206 | model_path: Path to VTP HuggingFace model directory |
| 207 | data_path: Path to ImageNet validation dataset |
| 208 | output_path: Output directory for reconstructed images |
| 209 | device: Device to use (ignored if use_ddp=True) |
| 210 | batch_size: Batch size per GPU |
| 211 | precision: Precision for inference (fp32, fp16, bf16) |
| 212 | save_images: Whether to save reconstructed images |
| 213 | use_ddp: Whether to use Distributed Data Parallel |
| 214 | num_workers: Number of dataloader workers |
| 215 | max_samples: Maximum number of samples to process (None for all) |
| 216 | """ |
| 217 | # Initialize DDP if needed |
| 218 | if use_ddp: |
| 219 | if not dist.is_initialized(): |
| 220 | dist.init_process_group(backend='nccl') |
| 221 | local_rank = dist.get_rank() |
| 222 | world_size = dist.get_world_size() |
| 223 | torch.cuda.set_device(local_rank) |
| 224 | device = torch.device(f'cuda:{local_rank}') |
| 225 | is_main = (local_rank == 0) |
| 226 | else: |
| 227 | local_rank, world_size = 0, 1 |
| 228 | device = torch.device(device) |
| 229 | is_main = True |
| 230 | |
| 231 | if is_main: |
| 232 | print("=" * 60) |
| 233 | print("ImageNet Reconstruction Evaluation (VTP HuggingFace)") |
| 234 | print("=" * 60) |
| 235 | print(f"Model path: {model_path}") |
| 236 | print(f"Data path: {data_path}") |
| 237 | print(f"Device: {device}" + (f", DDP: {world_size} GPUs" if use_ddp else "")) |
| 238 | print(f"Precision: {precision}") |
| 239 | print(f"Batch size: {batch_size}") |
| 240 | print() |
| 241 | |
| 242 | # Load model |
| 243 | if is_main: |
| 244 | print("Loading model...") |
| 245 | model = VTPModel.from_pretrained(model_path) |
| 246 | model = model.to(device) |
| 247 | model.eval() |
| 248 |
no test coverage detected