Inference analysis given the configs and inputs. Args: batch_size_per_gpu (int, optional): batch size per gpu. Defaults to 1. seq_len (int, optional): number of input tokens. Defaults to 512. num_tokens_to_generate (int, optional): number of tokens to gen
(
self,
batch_size_per_gpu: int = 1,
seq_len: int = 512,
num_tokens_to_generate: int = 32,
use_kv_cache: bool = True,
ds_zero: DSZeRO = DSZeRO.NONE,
layernorm_dtype_bytes: int = BYTES_FP16,
kv_cache_dtype_bytes: int = None,
cost_per_gpu_hour: float = None,
output_dir: str = None,
output_file_suffix: str = "",
)
| 1419 | ) |
| 1420 | |
| 1421 | def inference( |
| 1422 | self, |
| 1423 | batch_size_per_gpu: int = 1, |
| 1424 | seq_len: int = 512, |
| 1425 | num_tokens_to_generate: int = 32, |
| 1426 | use_kv_cache: bool = True, |
| 1427 | ds_zero: DSZeRO = DSZeRO.NONE, |
| 1428 | layernorm_dtype_bytes: int = BYTES_FP16, |
| 1429 | kv_cache_dtype_bytes: int = None, |
| 1430 | cost_per_gpu_hour: float = None, |
| 1431 | output_dir: str = None, |
| 1432 | output_file_suffix: str = "", |
| 1433 | ) -> dict: |
| 1434 | """Inference analysis given the configs and inputs. |
| 1435 | |
| 1436 | Args: |
| 1437 | batch_size_per_gpu (int, optional): batch size per gpu. Defaults to 1. |
| 1438 | seq_len (int, optional): number of input tokens. Defaults to 512. |
| 1439 | num_tokens_to_generate (int, optional): number of tokens to generate for generative models. Defaults to 32. |
| 1440 | use_kv_cache (bool, optional): whether to use kv_cache. Defaults to True. |
| 1441 | ds_zero (DSZeRO, optional): which DeepSpeed ZeRO stage to use. Defaults to DSZeRO.NONE (disabled). |
| 1442 | layernorm_dtype_bytes (int, optional): number of bytes in the data type for the layernorm activations. Defaults to BYTES_FP32. Often has to be at least FP16 in inference to maintain model accuracy. |
| 1443 | kv_cache_dtype_bytes (int, optional): number of bytes in the data type for the kv_cache. Defaults to None. Often has to be at least FP16 in inference to maintain model accuracy. |
| 1444 | cost_per_gpu_hour (float, optional): dollar cost per GPU hour. Defaults to None. |
| 1445 | output_dir (str, optional): if set to a directory path, write the return summary dict out to the directory with the setup. Defaults to None. |
| 1446 | output_dir (str, optional): if set to a directory path, write the return summary dict out to the directory with the setup. Defaults to None. |
| 1447 | |
| 1448 | Returns: |
| 1449 | dict: a summary dict of the training analysis |
| 1450 | """ |
| 1451 | if self.model_config.max_seq_len is not None: |
| 1452 | assert ( |
| 1453 | seq_len <= self.model_config.max_seq_len |
| 1454 | ), f"seq_len must be less than model max_seq_len ({self.model_config.max_seq_len})" |
| 1455 | |
| 1456 | self.print_config("Inference Configs") |
| 1457 | |
| 1458 | logger.info(f"\n{'Analysis'.center(PRINT_LINE_WIDTH, '-')}") |
| 1459 | |
| 1460 | if kv_cache_dtype_bytes is None: |
| 1461 | kv_cache_dtype_bytes = (self.dtype_config.activation_bits / |
| 1462 | BITS_PER_BYTE) |
| 1463 | logger.info( |
| 1464 | "kv_cache_dtype_bytes not specified, setting to the same as" |
| 1465 | f" the activation data type : {kv_cache_dtype_bytes}") |
| 1466 | |
| 1467 | num_layers_per_gpu = int(self.model_config.num_layers / |
| 1468 | self.parallelism_config.pp_size) |
| 1469 | if self.model_config.num_layers % self.parallelism_config.pp_size: |
| 1470 | logger.info( |
| 1471 | "num_layers not be divisible by pp_size, taking the floor") |
| 1472 | |
| 1473 | weight_memory_embedding_per_gpu = self.get_memory_embedding(ds_zero) |
| 1474 | weight_memory_layers_per_gpu, weight_memory_attn_per_gpu, weight_memory_mlp_per_gpu, weight_memory_layernorm_per_gpu = [ |
| 1475 | x * self.model_config.num_layers |
| 1476 | for x in self.get_weight_memory_per_layer(ds_zero, |
| 1477 | return_breakdown=True) |
| 1478 | ] |