(
dp_size,
dp_rank,
dp_master_ip,
dp_master_port,
GPUs_per_dp_rank,
model_name_or_path,
samples,
output_path,
model_name,
temperature,
lock,
)
| 104 | |
| 105 | |
| 106 | def main( |
| 107 | dp_size, |
| 108 | dp_rank, |
| 109 | dp_master_ip, |
| 110 | dp_master_port, |
| 111 | GPUs_per_dp_rank, |
| 112 | model_name_or_path, |
| 113 | samples, |
| 114 | output_path, |
| 115 | model_name, |
| 116 | temperature, |
| 117 | lock, |
| 118 | ): |
| 119 | os.environ["VLLM_DP_RANK"] = str(dp_rank) |
| 120 | os.environ["VLLM_DP_SIZE"] = str(dp_size) |
| 121 | os.environ["VLLM_DP_MASTER_IP"] = dp_master_ip |
| 122 | os.environ["VLLM_DP_MASTER_PORT"] = str(dp_master_port) |
| 123 | # set devices for each dp_rank |
| 124 | os.environ["CUDA_VISIBLE_DEVICES"] = ",".join( |
| 125 | str(i) |
| 126 | for i in range(dp_rank * GPUs_per_dp_rank, (dp_rank + 1) * GPUs_per_dp_rank) |
| 127 | ) |
| 128 | print(f"DP rank {dp_rank} needs to process {len(samples)} prompts") |
| 129 | |
| 130 | # Create a sampling params object. |
| 131 | # since we are doing data parallel, every rank can have different |
| 132 | # sampling params. here we set different max_tokens for different |
| 133 | # ranks for demonstration. |
| 134 | sampling_params = SamplingParams( |
| 135 | temperature=temperature, |
| 136 | top_p=1.0, |
| 137 | # top_k=50, |
| 138 | max_tokens=4096 |
| 139 | ) |
| 140 | |
| 141 | # Create an LLM. |
| 142 | llm = LLM( |
| 143 | model=model_name_or_path, |
| 144 | tensor_parallel_size=GPUs_per_dp_rank, |
| 145 | enforce_eager=False, |
| 146 | # max_model_len=32768, |
| 147 | gpu_memory_utilization=0.8, |
| 148 | dtype='bfloat16', |
| 149 | ) |
| 150 | convs = [] |
| 151 | for sample in samples: |
| 152 | ctx = [] |
| 153 | for i in range(0, len(sample['context']), 2): |
| 154 | ctx.append(f'Q{i // 2 + 1}: {sample["context"][i]}') |
| 155 | ctx.append(f'A{i // 2 + 1}: {sample["context"][i + 1]}') |
| 156 | convs.append([ |
| 157 | { |
| 158 | 'role': 'user', |
| 159 | 'content': INSTRUCTION.format( |
| 160 | context='\n'.join(ctx), |
| 161 | query=sample['question'] |
| 162 | ) |
| 163 | } |
nothing calls this directly
no test coverage detected