Collect platform information and send it to the usage stats server.
| 247 | |
| 248 | |
| 249 | class UsageMessage: |
| 250 | """Collect platform information and send it to the usage stats server.""" |
| 251 | |
| 252 | def __init__(self) -> None: |
| 253 | |
| 254 | self.uuid = str(uuid4()) |
| 255 | |
| 256 | # Environment Information |
| 257 | self.provider: str | None = None |
| 258 | self.cpu_num: int | None = None |
| 259 | self.cpu_type: str | None = None |
| 260 | self.cpu_family_model_stepping: str | None = None |
| 261 | self.total_memory: int | None = None |
| 262 | self.architecture: str | None = None |
| 263 | self.platform: str | None = None |
| 264 | self.cuda_runtime: str | None = None |
| 265 | self.gpu_num: int | None = None |
| 266 | self.gpu_type: str | None = None |
| 267 | self.gpu_memory_per_device: int | None = None |
| 268 | self.env_var_json: str | None = None |
| 269 | |
| 270 | # FD Information |
| 271 | self.model_architecture: str | None = None |
| 272 | self.fd_version: str | None = None |
| 273 | self.num_layers: int | None = None |
| 274 | |
| 275 | # Metadata |
| 276 | self.log_time: int | None = None |
| 277 | self.source: str | None = None |
| 278 | self.config: str | None = None |
| 279 | |
| 280 | def report_usage(self, fd_config: FDConfig, extra_kvs: dict[str, Any] | None = None) -> None: |
| 281 | t = Thread( |
| 282 | target=self._report_usage_worker, |
| 283 | args=( |
| 284 | fd_config, |
| 285 | extra_kvs, |
| 286 | ), |
| 287 | daemon=True, |
| 288 | ) |
| 289 | t.start() |
| 290 | |
| 291 | def _report_usage_worker(self, fd_config: FDConfig, extra_kvs: dict[str, Any]) -> None: |
| 292 | self._report_usage_once(fd_config, extra_kvs) |
| 293 | self._report_continuous_usage() |
| 294 | |
| 295 | def _report_usage_once(self, fd_config: FDConfig, extra_kvs: dict[str, Any]): |
| 296 | if current_platform.is_cuda_alike(): |
| 297 | self.gpu_num = cuda_device_count() |
| 298 | self.gpu_type, self.gpu_memory_per_device = cuda_get_device_properties(0, ("name", "total_memory")) |
| 299 | if current_platform.is_xpu(): |
| 300 | self.gpu_num = xpu_device_count() |
| 301 | self.gpu_type = get_xpu_model() |
| 302 | self.gpu_memory_per_device = paddle.device.xpu.memory_total() |
| 303 | if current_platform.is_cuda(): |
| 304 | self.cuda_runtime = get_cuda_version() |
| 305 | self.provider = detect_cloud_provider() |
| 306 | self.architecture = platform.machine() |
no outgoing calls