compressed_tensors.entrypoints.convert.convert_checkpoint
Functions:
-
convert_checkpoint–Convert a model checkpoint to either:
-
exec_jobs–Execute jobs in parallel, using ThreadPoolExecutor
convert_checkpoint
convert_checkpoint(model_stub: str | PathLike, save_directory: str | PathLike, converter: Converter | list[Converter], max_workers: int | Literal['auto'] = 'auto', device: str | device | list[str | device] | None = None, job_memory_estimator: Callable[[InverseWeightMap, list[Converter]], int] = estimate_job_memory)
Convert a model checkpoint to either: - its equivalent quantized format in compressed-tensors - the unquantized format without loading it up in memory, instead operating directly on the model safetensors files. This entrypoint operates on a model stub or folder containing weights saved in safetensors files, and updates the corresponding quantization_config field in the config.json. All additional files will be copied to new checkpoint.
Parameters:
-
model_stub(str | PathLike) –huggingface model hub or path to local weights files
-
save_directory(str | PathLike) –new checkpoint will be saved in this directory.
-
max_workers(int | Literal['auto'], default:'auto') –number of worker threads to process files with. If "auto" (default), the number of workers is chosen from the number of safetensors files, the estimated memory of each conversion job, the free memory of each accelerator, and the number of CPUs available to this process. Host memory is not taken into account, so pass a smaller number of workers if conversion runs out of host memory
-
device(str | device | list[str | device] | None, default:None) –device or devices on which to run conversion. When omitted, all available accelerator devices are used, falling back to CPU when no accelerator is available.
-
job_memory_estimator(Callable[[InverseWeightMap, list[Converter]], int], default:estimate_job_memory) –callable returning the estimated memory in bytes for a conversion job, given its inverse weight map and the converters to apply. Defaults to a meta-tensor profiler; used only for accelerator scheduling.
-
converter(Converter | list[Converter]) –single converter or list of converters to apply in order, e.g. a dequantizer followed by a re-quantizer
Source code in src/compressed_tensors/entrypoints/convert/convert_checkpoint.py
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 | |
exec_jobs
exec_jobs(jobs: list[tuple[Callable, ...]], max_workers: int = 1, desc: str = 'Executing Jobs') -> list
Execute jobs in parallel, using ThreadPoolExecutor
Parameters:
-
jobs(list[tuple[Callable, ...]]) –list of tuples, the first entry of which is the callable, and the remaining elements are the inputs args to the callable
-
max_workers(int, default:1) –number of workers to use
-
desc(str, default:'Executing Jobs') –tqdm description