For each profile, validate that the named dimensions of different input tensors in this profile all have same range. TRT will validate the same condition, validate it earlier to make sure the modeling in TensorRT LLM are correct and makes the error msg more user
(self, network: Network,
builder_config)
| 274 | ), "Validation of the tensor dimension ranges failed, please check the dimension ranges, find the offensive tensor and dimension name in above the error log" |
| 275 | |
| 276 | def _validate_named_dimensions(self, network: Network, |
| 277 | builder_config) -> bool: |
| 278 | ''' |
| 279 | For each profile, validate that the named dimensions of different input tensors in this profile all have same range. |
| 280 | TRT will validate the same condition, validate it earlier to make sure the modeling in TensorRT LLM are correct and |
| 281 | makes the error msg more user friendly. |
| 282 | ''' |
| 283 | valid = True |
| 284 | for profile_idx in range( |
| 285 | builder_config.trt_builder_config.num_optimization_profiles): |
| 286 | dimension_to_range = {} |
| 287 | for input_name, input_tensor in network._inputs.items(): |
| 288 | # it's legal that a Tensor does not have dim_range? |
| 289 | if len(input_tensor.profiles) != 0: |
| 290 | profile = input_tensor.profiles[profile_idx] |
| 291 | for dim_idx, dim_name in enumerate(profile.dimension_names): |
| 292 | if dim_name not in dimension_to_range: |
| 293 | dimension_to_range[dim_name] = [] |
| 294 | min, opt, max = profile.min[dim_idx], profile.opt[ |
| 295 | dim_idx], profile.max[dim_idx] |
| 296 | dimension_to_range[dim_name].append( |
| 297 | (input_name, (min, opt, max))) |
| 298 | for dim, ranges in dimension_to_range.items(): |
| 299 | unique_ranges = set([r[1] for r in ranges]) |
| 300 | logger.debug( |
| 301 | f"Validating dimension:{dim}, ranges for this dim are:{unique_ranges}" |
| 302 | ) |
| 303 | if len(unique_ranges) != 1: |
| 304 | logger.error( |
| 305 | f"Found illegal dimension setting for profile {profile_idx}, dimension name is: {dim}" |
| 306 | ) |
| 307 | logger.error( |
| 308 | "Offensive tensors which have this dimension are:\n" + |
| 309 | "\n".join([f"{r[1]} {dim} {r[0]}" for r in ranges])) |
| 310 | valid = False |
| 311 | return valid |
| 312 | |
| 313 | @_is_building |
| 314 | def refit_engine(self, network: Network, engine_buffer) -> trt.IHostMemory: |
no test coverage detected