in pplbench/lib/ppl_helper.py [0:0]
def find_ppl_details(config: SimpleNamespace) -> List[PPLDetails]:
"""
Returns information about each instance of PPL inference that is requested
in the benchmark.
This raises a Runtime exception if the names are not unique.
:param config: The benchmark configuration object.
:returns: A list of information objects one per ppl inference.
"""
ret_val = []
prev_names = set()
model_class = getattr(config.model, "class")
for ppl_config in config.ppls:
package = getattr(ppl_config, "package", "pplbench.ppls." + ppl_config.name)
impl_class = load_class_or_exit(f"{package}.{model_class}")
inference_class = load_class_or_exit(
f"{package}.{getattr(ppl_config.inference, 'class')}"
)
# create a unique name for the PPL inference if not given
name = (
ppl_config.legend.name
if hasattr(ppl_config, "legend") and hasattr(ppl_config.legend, "name")
else ppl_config.name + "-" + inference_class.__name__
)
if name in prev_names:
raise RuntimeError(f"duplicate PPL inference {name}")
prev_names.add(name)
# we will generate a unique color for each ppl name
# https://stackoverflow.com/questions/40351791/how-to-hash-strings-into-a-float-in-01
def _hash(name):
return (
float(
struct.unpack(
"L", hashlib.sha256(bytes(name, "utf-8")).digest()[:8]
)[0]
)
/ 2 ** 64
)
def _get_color(name):
return (_hash(name + "0"), _hash(name + "1"), _hash(name + "1"))
if hasattr(ppl_config, "legend") and hasattr(ppl_config.legend, "color"):
if is_color_like(ppl_config.legend.color):
color = to_rgb(ppl_config.legend.color)
else:
raise RuntimeError(
f"invalid color '{ppl_config.legend.color}' for PPL inference '{name}'"
)
else:
color = _get_color(name)
# finally pick a default seed for the ppl
seed = getattr(ppl_config, "seed", int(time.time() + 19))
infer = ppl_config.inference
ret_val.append(
PPLDetails(
name=name,
seed=seed,
color=color,
impl_class=impl_class,
inference_class=inference_class,
num_warmup=getattr(infer, "num_warmup", None),
compile_args=infer.compile_args.__dict__
if hasattr(infer, "compile_args")
else {},
infer_args=infer.infer_args.__dict__
if hasattr(infer, "infer_args")
else {},
)
)
LOGGER.debug(f"added PPL inference '{str(ret_val[-1])}'")
return ret_val