__version__='1.3.3'importosimportsubprocessimportsysfromloguruimportlogger# allow loading truncated images for some too large images.fromPILimportImageFilefromdata_juicer.utils.availability_utilsimport_is_package_availablefromdata_juicer.utils.lazy_loaderimportLazyLoadertorch=LazyLoader('torch')ImageFile.LOAD_TRUNCATED_IMAGES=True# For now, only INFO will be shown. Later the severity level will be changed# when setup_logger is called to initialize the logger.logger.remove()logger.add(sys.stderr,level='INFO')def_cuda_device_count():_torch_available=_is_package_available('torch')if_torch_available:returntorch.cuda.device_count()try:nvidia_smi_output=subprocess.check_output(['nvidia-smi','-L'],text=True)all_devices=nvidia_smi_output.strip().split('\n')cuda_visible_devices=os.getenv('CUDA_VISIBLE_DEVICES')ifcuda_visible_devicesisnotNone:logger.warning('CUDA_VISIBLE_DEVICES is ignored when torch is unavailable. ''All detected GPUs will be used.')returnlen(all_devices)exceptException:# nvidia-smi not found or other errorreturn0