| 51 | |
| 52 | |
| 53 | class BuilderConfig(object): |
| 54 | |
| 55 | def __init__(self, **kwargs): |
| 56 | # intentionally use **kwargs, user should never call this ctor directly, |
| 57 | # use Builder.create_builder_config() instead |
| 58 | pass |
| 59 | |
| 60 | def _init(self, trt_builder_config, **kwargs): |
| 61 | self._trt_builder_config = trt_builder_config |
| 62 | for key, value in kwargs.items(): |
| 63 | setattr(self, key, value) |
| 64 | return self |
| 65 | |
| 66 | @property |
| 67 | def trt_builder_config(self) -> trt.IBuilderConfig: |
| 68 | return self._trt_builder_config |
| 69 | |
| 70 | def to_dict(self) -> Dict: |
| 71 | '''return a dict with keys |
| 72 | { |
| 73 | "builder_config": { |
| 74 | # all key values set by the _init function |
| 75 | }, |
| 76 | "plugin_config": { |
| 77 | # the network plugin_config (if any) attached to this BuilderConfig object |
| 78 | # inside the Builder.build_engine |
| 79 | } |
| 80 | } |
| 81 | ''' |
| 82 | config = {'builder_config': {}} |
| 83 | for k in self.__dict__.keys(): |
| 84 | if k not in ['_trt_builder_config', 'plugin_config']: |
| 85 | config['builder_config'][k] = self.__getattribute__(k) |
| 86 | if hasattr(self, 'plugin_config'): |
| 87 | assert isinstance(self.plugin_config, PluginConfig), \ |
| 88 | f"Found unexpected plugin_config object with type: {type(self.plugin_config)}" |
| 89 | config['plugin_config'] = self.plugin_config.model_dump(mode="json") |
| 90 | return config |
| 91 | |
| 92 | |
| 93 | class Builder(): |
no outgoing calls
no test coverage detected