[diffusion] logging: improve logging (#19312)
This commit is contained in:
@@ -47,7 +47,7 @@ def _maybe_download_model(
|
|||||||
from sglang.multimodal_gen.runtime.utils.hf_diffusers_utils import hf_hub_download
|
from sglang.multimodal_gen.runtime.utils.hf_diffusers_utils import hf_hub_download
|
||||||
|
|
||||||
if os.path.exists(model_name_or_path):
|
if os.path.exists(model_name_or_path):
|
||||||
logger.info("Model already exists locally")
|
logger.debug("Model already exists locally")
|
||||||
return model_name_or_path
|
return model_name_or_path
|
||||||
|
|
||||||
if not download:
|
if not download:
|
||||||
@@ -57,7 +57,7 @@ def _maybe_download_model(
|
|||||||
# Try `model_index.json` first (diffusers models)
|
# Try `model_index.json` first (diffusers models)
|
||||||
source_hub = "MS Hub" if envs.SGLANG_USE_MODELSCOPE.get() else "HF Hub"
|
source_hub = "MS Hub" if envs.SGLANG_USE_MODELSCOPE.get() else "HF Hub"
|
||||||
try:
|
try:
|
||||||
logger.info(
|
logger.debug(
|
||||||
"Downloading model_index.json from %s for %s...",
|
"Downloading model_index.json from %s for %s...",
|
||||||
source_hub,
|
source_hub,
|
||||||
model_name_or_path,
|
model_name_or_path,
|
||||||
@@ -67,14 +67,14 @@ def _maybe_download_model(
|
|||||||
filename="model_index.json",
|
filename="model_index.json",
|
||||||
local_dir=local_dir,
|
local_dir=local_dir,
|
||||||
)
|
)
|
||||||
logger.info("Downloaded to %s", file_path)
|
logger.debug("Downloaded to %s", file_path)
|
||||||
return os.path.dirname(file_path)
|
return os.path.dirname(file_path)
|
||||||
except Exception as e_index:
|
except Exception as e_index:
|
||||||
logger.debug("model_index.json not found or failed: %s", e_index)
|
logger.debug("model_index.json not found or failed: %s", e_index)
|
||||||
|
|
||||||
# Fallback to `config.json`
|
# Fallback to `config.json`
|
||||||
try:
|
try:
|
||||||
logger.info(
|
logger.debug(
|
||||||
"Downloading config.json from %s for %s...",
|
"Downloading config.json from %s for %s...",
|
||||||
source_hub,
|
source_hub,
|
||||||
model_name_or_path,
|
model_name_or_path,
|
||||||
@@ -84,7 +84,7 @@ def _maybe_download_model(
|
|||||||
filename="config.json",
|
filename="config.json",
|
||||||
local_dir=local_dir,
|
local_dir=local_dir,
|
||||||
)
|
)
|
||||||
logger.info("Downloaded to %s", file_path)
|
logger.debug("Downloaded to %s", file_path)
|
||||||
return os.path.dirname(file_path)
|
return os.path.dirname(file_path)
|
||||||
except Exception as e_config:
|
except Exception as e_config:
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
|
|||||||
@@ -423,13 +423,13 @@ def get_model_info(
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
# 4. Combine and return the complete model info
|
# 4. Combine and return the complete model info
|
||||||
logger.info("Using native sglang backend for model '%s'", model_path)
|
logger.debug("Using native sglang backend for model '%s'", model_path)
|
||||||
model_info = ModelInfo(
|
model_info = ModelInfo(
|
||||||
pipeline_cls=pipeline_cls,
|
pipeline_cls=pipeline_cls,
|
||||||
sampling_param_cls=config_info.sampling_param_cls,
|
sampling_param_cls=config_info.sampling_param_cls,
|
||||||
pipeline_config_cls=config_info.pipeline_config_cls,
|
pipeline_config_cls=config_info.pipeline_config_cls,
|
||||||
)
|
)
|
||||||
logger.info(f"Found model info: {model_info}")
|
logger.debug(f"Found model info: {model_info}")
|
||||||
|
|
||||||
return model_info
|
return model_info
|
||||||
|
|
||||||
|
|||||||
@@ -125,35 +125,16 @@ class ComponentLoader(ABC):
|
|||||||
if isinstance(component, nn.Module):
|
if isinstance(component, nn.Module):
|
||||||
component = component.eval()
|
component = component.eval()
|
||||||
current_gpu_mem = current_platform.get_available_gpu_memory()
|
current_gpu_mem = current_platform.get_available_gpu_memory()
|
||||||
model_size = get_memory_usage_of_component(component)
|
model_size = get_memory_usage_of_component(component) or "NA"
|
||||||
consumed = gpu_mem_before_loading - current_gpu_mem
|
consumed = gpu_mem_before_loading - current_gpu_mem
|
||||||
|
|
||||||
# detect component device
|
|
||||||
try:
|
|
||||||
component_device = str(next(component.parameters()).device)
|
|
||||||
is_on_gpu = "cuda" in component_device
|
|
||||||
except (StopIteration, AttributeError):
|
|
||||||
is_on_gpu = False
|
|
||||||
component_device = "unknown"
|
|
||||||
|
|
||||||
if is_on_gpu:
|
|
||||||
logger.info(
|
logger.info(
|
||||||
f"Loaded %s: %s ({source} version). model size: %.2f GB, consumed GPU: %.2f GB, avail GPU mem: %.2f GB",
|
f"Loaded %s: %s ({source} version). model size: %s GB, consumed GPU mem: %.2f GB, avail GPU mem: %.2f GB",
|
||||||
component_name,
|
component_name,
|
||||||
component.__class__.__name__,
|
component.__class__.__name__,
|
||||||
model_size,
|
model_size,
|
||||||
consumed,
|
consumed,
|
||||||
current_gpu_mem,
|
current_gpu_mem,
|
||||||
)
|
)
|
||||||
else:
|
|
||||||
logger.info(
|
|
||||||
f"Loaded %s: %s ({source} version). model size: %.2f GB, device: %s, avail GPU mem: %.2f GB",
|
|
||||||
component_name,
|
|
||||||
component.__class__.__name__,
|
|
||||||
model_size,
|
|
||||||
component_device,
|
|
||||||
current_gpu_mem,
|
|
||||||
)
|
|
||||||
return component, consumed
|
return component, consumed
|
||||||
|
|
||||||
def load_native(
|
def load_native(
|
||||||
|
|||||||
@@ -282,7 +282,7 @@ class Req:
|
|||||||
return pprint.pformat(asdict(self), indent=2, width=120)
|
return pprint.pformat(asdict(self), indent=2, width=120)
|
||||||
|
|
||||||
def log(self, server_args: ServerArgs):
|
def log(self, server_args: ServerArgs):
|
||||||
if self.is_warmup:
|
if self.is_warmup or self.suppress_logs:
|
||||||
return
|
return
|
||||||
# TODO: in some cases (e.g., TI2I), height and weight might be undecided at this moment
|
# TODO: in some cases (e.g., TI2I), height and weight might be undecided at this moment
|
||||||
if self.height:
|
if self.height:
|
||||||
@@ -300,8 +300,8 @@ class Req:
|
|||||||
self.negative_prompt, key_hint="negative_prompt"
|
self.negative_prompt, key_hint="negative_prompt"
|
||||||
)
|
)
|
||||||
|
|
||||||
# log non-sensitive parameters at info level
|
# Log sampling parameters
|
||||||
info_str = f"""Sampling params:
|
debug_str = f"""Sampling params:
|
||||||
width: {target_width}
|
width: {target_width}
|
||||||
height: {target_height}
|
height: {target_height}
|
||||||
num_frames: {self.num_frames}
|
num_frames: {self.num_frames}
|
||||||
@@ -319,15 +319,6 @@ class Req:
|
|||||||
save_output: {self.save_output}
|
save_output: {self.save_output}
|
||||||
output_file_path: {self.output_file_path()}
|
output_file_path: {self.output_file_path()}
|
||||||
""" # type: ignore[attr-defined]
|
""" # type: ignore[attr-defined]
|
||||||
|
|
||||||
# log full prompts at debug level only (for debugging purposes)
|
|
||||||
debug_str = f"""Full prompts:
|
|
||||||
prompt: {self.prompt}
|
|
||||||
neg_prompt: {self.negative_prompt}
|
|
||||||
"""
|
|
||||||
|
|
||||||
if not self.suppress_logs:
|
|
||||||
logger.info(info_str)
|
|
||||||
logger.debug(debug_str)
|
logger.debug(debug_str)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -605,7 +605,7 @@ def maybe_download_model_index(model_name_or_path: str) -> dict[str, Any]:
|
|||||||
# Add the pipeline name for downstream use
|
# Add the pipeline name for downstream use
|
||||||
config["pipeline_name"] = config["_class_name"]
|
config["pipeline_name"] = config["_class_name"]
|
||||||
|
|
||||||
logger.info(
|
logger.debug(
|
||||||
"Downloaded model_index.json for %s, pipeline: %s",
|
"Downloaded model_index.json for %s, pipeline: %s",
|
||||||
model_name_or_path,
|
model_name_or_path,
|
||||||
config["_class_name"],
|
config["_class_name"],
|
||||||
|
|||||||
Reference in New Issue
Block a user