method_name
stringlengths
3
45
method_body
stringlengths
9
6.25k
full_code
stringlengths
35
7.02k
docstring
stringlengths
18
4.7k
forward
if residual is None: residual = hidden_states hidden_states = self.input_layernorm(hidden_states) else: hidden_states, residual = self.input_layernorm(hidden_states, residual) hidden_states = self.self_attn(positions=positions, hidden_states= hidden_states, kv_cache=kv_cache, input_metadata=input_metada...
def forward(self, positions: torch.Tensor, hidden_states: torch.Tensor, kv_cache: KVCache, input_metadata: InputMetadata, residual: Optional[ torch.Tensor]) ->Tuple[torch.Tensor, torch.Tensor]: if residual is None: residual = hidden_states hidden_states = self.input_layernorm(hidden_states) ...
null
__init__
super().__init__() self.hidden_size = hidden_size tp_size = get_tensor_model_parallel_world_size() self.total_num_heads = num_heads assert self.total_num_heads % tp_size == 0 self.num_heads = self.total_num_heads // tp_size self.total_num_kv_heads = num_kv_heads if self.total_num_kv_heads >= tp_size: assert self.to...
def __init__(self, hidden_size: int, num_heads: int, num_kv_heads: int, max_position: int=4096 * 32, rope_theta: float=10000, linear_method: Optional[LinearMethodBase]=None, sliding_window: Optional[int]=None ) ->None: super().__init__() self.hidden_size = hidden_size tp_size = get_tensor_model_...
null
__init__
super().__init__() self.hidden_size = hidden_size tp_size = get_tensor_model_parallel_world_size() self.total_num_heads = num_heads assert self.total_num_heads % tp_size == 0 self.num_heads = self.total_num_heads // tp_size self.total_num_kv_heads = num_kv_heads assert self.total_num_kv_heads % tp_size == 0 self.num_kv...
def __init__(self, hidden_size: int, num_heads: int, num_kv_heads: int, rope_theta: float=10000, max_position_embeddings: int=8192, rope_scaling: Optional[Dict[str, Any]]=None, linear_method: Optional[ LinearMethodBase]=None): super().__init__() self.hidden_size = hidden_size tp_size = get_tenso...
null
__init__
super().__init__() self.use_parallel_residual = config.use_parallel_residual self.input_layernorm = nn.LayerNorm(config.hidden_size, eps=config. layer_norm_eps) self.post_attention_layernorm = nn.LayerNorm(config.hidden_size, eps=config .layer_norm_eps) self.attention = GPTNeoXAttention(config, linear_method) s...
def __init__(self, config: GPTNeoXConfig, linear_method: Optional[ LinearMethodBase]=None): super().__init__() self.use_parallel_residual = config.use_parallel_residual self.input_layernorm = nn.LayerNorm(config.hidden_size, eps=config. layer_norm_eps) self.post_attention_layernorm = nn.Laye...
null
forward
hidden_states = self.gpt_neox(input_ids, positions, kv_caches, input_metadata) return hidden_states
def forward(self, input_ids: torch.Tensor, positions: torch.Tensor, kv_caches: List[KVCache], input_metadata: InputMetadata) ->torch.Tensor: hidden_states = self.gpt_neox(input_ids, positions, kv_caches, input_metadata) return hidden_states
null
forward
x, _ = self.up_proj(x) x = self.act(x) x, _ = self.down_proj(x) return x
def forward(self, x: torch.Tensor) ->torch.Tensor: x, _ = self.up_proj(x) x = self.act(x) x, _ = self.down_proj(x) return x
null
forward
hidden_states = self.transformer(input_ids, positions, kv_caches, input_metadata) return hidden_states
def forward(self, input_ids: torch.Tensor, positions: torch.Tensor, kv_caches: List[KVCache], input_metadata: InputMetadata) ->torch.Tensor: hidden_states = self.transformer(input_ids, positions, kv_caches, input_metadata) return hidden_states
null
can_swap_in
blocks = self._get_physical_blocks(seq_group) num_swapped_seqs = seq_group.num_seqs(status=SequenceStatus.SWAPPED) num_free_blocks = self.gpu_allocator.get_num_free_blocks() num_required_blocks = len(blocks) + num_swapped_seqs return num_free_blocks - num_required_blocks >= self.watermark_blocks
def can_swap_in(self, seq_group: SequenceGroup) ->bool: blocks = self._get_physical_blocks(seq_group) num_swapped_seqs = seq_group.num_seqs(status=SequenceStatus.SWAPPED) num_free_blocks = self.gpu_allocator.get_num_free_blocks() num_required_blocks = len(blocks) + num_swapped_seqs return num_free_b...
null
__next__
i = self.counter self.counter += 1 return i
def __next__(self) ->int: i = self.counter self.counter += 1 return i
null
forward
bias = self.bias if not self.skip_bias_add else None output_parallel = self.linear_method.apply_weights(self.linear_weights, input_, bias) if self.gather_output: output = tensor_model_parallel_all_gather(output_parallel) else: output = output_parallel output_bias = self.bias if self.skip_bias_add else None ...
def forward(self, input_): bias = self.bias if not self.skip_bias_add else None output_parallel = self.linear_method.apply_weights(self.linear_weights, input_, bias) if self.gather_output: output = tensor_model_parallel_all_gather(output_parallel) else: output = output_parallel ...
null
has_unfinished_requests
"""Returns True if there are unfinished requests.""" return self.scheduler.has_unfinished_seqs()
def has_unfinished_requests(self) ->bool: """Returns True if there are unfinished requests.""" return self.scheduler.has_unfinished_seqs()
Returns True if there are unfinished requests.
run_benchmark
torch.cuda.synchronize() if profile: torch.cuda.cudart().cudaProfilerStart() start_time = time.perf_counter() for _ in range(num_iters): if version == 'v1': ops.paged_attention_v1(output, query, key_cache, value_cache, num_kv_heads, scale, block_tables, context_lens, block_size, ...
def run_benchmark(num_iters: int, profile: bool=False) ->float: torch.cuda.synchronize() if profile: torch.cuda.cudart().cudaProfilerStart() start_time = time.perf_counter() for _ in range(num_iters): if version == 'v1': ops.paged_attention_v1(output, query, key_cache, value_...
null
__init__
super().__init__() self.total_num_heads = config.num_attention_heads self.hidden_size = config.hidden_size self.head_size = self.hidden_size // self.total_num_heads self.qkv_proj = QKVParallelLinear(config.hidden_size, self.head_size, self. total_num_heads, bias=False, linear_method=linear_method) self.out_proj = R...
def __init__(self, config: GPTJConfig, linear_method: Optional[ LinearMethodBase]=None): super().__init__() self.total_num_heads = config.num_attention_heads self.hidden_size = config.hidden_size self.head_size = self.hidden_size // self.total_num_heads self.qkv_proj = QKVParallelLinear(config.h...
null
abort_request
"""Abort a request during next background loop iteration.""" if verbose: logger.info(f'Aborted request {request_id}.') self._finished_requests.put_nowait(request_id) if request_id not in self._request_streams or self._request_streams[request_id ].finished: return self._request_streams[request_id].finish()
def abort_request(self, request_id: str, *, verbose: bool=False) ->None: """Abort a request during next background loop iteration.""" if verbose: logger.info(f'Aborted request {request_id}.') self._finished_requests.put_nowait(request_id) if request_id not in self._request_streams or self._reque...
Abort a request during next background loop iteration.
__init__
self.request_id = request_id self.seqs_dict = {seq.seq_id: seq for seq in seqs} self.sampling_params = sampling_params self.arrival_time = arrival_time self.prompt_logprobs: Optional[PromptLogprobs] = None
def __init__(self, request_id: str, seqs: List[Sequence], sampling_params: SamplingParams, arrival_time: float) ->None: self.request_id = request_id self.seqs_dict = {seq.seq_id: seq for seq in seqs} self.sampling_params = sampling_params self.arrival_time = arrival_time self.prompt_logprobs: Op...
null
forward
inputs_embeds = self.wte(input_ids) position_embeds = self.wpe(position_ids) hidden_states = inputs_embeds + position_embeds for i in range(len(self.h)): layer = self.h[i] hidden_states = layer(hidden_states, kv_caches[i], input_metadata) hidden_states = self.ln_f(hidden_states) return hidden_states
def forward(self, input_ids: torch.Tensor, position_ids: torch.Tensor, kv_caches: List[KVCache], input_metadata: InputMetadata) ->torch.Tensor: inputs_embeds = self.wte(input_ids) position_embeds = self.wpe(position_ids) hidden_states = inputs_embeds + position_embeds for i in range(len(self.h)): ...
null
_rotate_neox
x1 = x[..., :x.shape[-1] // 2] x2 = x[..., x.shape[-1] // 2:] return torch.cat((-x2, x1), dim=-1)
def _rotate_neox(x: torch.Tensor) ->torch.Tensor: x1 = x[..., :x.shape[-1] // 2] x2 = x[..., x.shape[-1] // 2:] return torch.cat((-x2, x1), dim=-1)
null
forward
out = torch.empty_like(x) ops.gelu_new(out, x) return out
def forward(self, x: torch.Tensor) ->torch.Tensor: out = torch.empty_like(x) ops.gelu_new(out, x) return out
null
forward
gate_up, _ = self.gate_up_proj(x) x = self.act_fn(gate_up) x, _ = self.c_proj(x) return x
def forward(self, x): gate_up, _ = self.gate_up_proj(x) x = self.act_fn(gate_up) x, _ = self.c_proj(x) return x
null
create_weights
del output_size if input_size_per_partition % self.quant_config.group_size != 0: raise ValueError( 'The input size is not aligned with the quantized weight shape. This can be caused by too large tensor parallel size.' ) if output_size_per_partition % self.quant_config.pack_factor != 0: raise Val...
def create_weights(self, input_size_per_partition: int, output_size_per_partition: int, input_size: int, output_size: int, params_dtype: torch.dtype) ->Dict[str, Any]: del output_size if input_size_per_partition % self.quant_config.group_size != 0: raise ValueError( 'The input size i...
null
warm_up_model
if not self.model_config.enforce_eager: self.model_runner.capture_model(self.gpu_cache) set_random_seed(self.model_config.seed)
def warm_up_model(self) ->None: if not self.model_config.enforce_eager: self.model_runner.capture_model(self.gpu_cache) set_random_seed(self.model_config.seed)
null
_setup_logger
_root_logger.setLevel(logging.DEBUG) global _default_handler if _default_handler is None: _default_handler = logging.StreamHandler(sys.stdout) _default_handler.flush = sys.stdout.flush _default_handler.setLevel(logging.INFO) _root_logger.addHandler(_default_handler) fmt = NewLineFormatter(_FORMAT, datef...
def _setup_logger(): _root_logger.setLevel(logging.DEBUG) global _default_handler if _default_handler is None: _default_handler = logging.StreamHandler(sys.stdout) _default_handler.flush = sys.stdout.flush _default_handler.setLevel(logging.INFO) _root_logger.addHandler(_defau...
null
__init__
self.hidden_size = hidden_size self.head_size = head_size self.total_num_heads = total_num_heads if total_num_kv_heads is None: total_num_kv_heads = total_num_heads self.total_num_kv_heads = total_num_kv_heads tp_size = get_tensor_model_parallel_world_size() self.num_heads = divide(self.total_num_heads, tp_size) if...
def __init__(self, hidden_size: int, head_size: int, total_num_heads: int, total_num_kv_heads: Optional[int]=None, bias: bool=True, skip_bias_add: bool=False, params_dtype: Optional[torch.dtype]=None, linear_method: Optional[LinearMethodBase]=None): self.hidden_size = hidden_size self.head_size = he...
null
__init__
super().__init__() hidden_size = config.hidden_size self.c_fc = ColumnParallelLinear(hidden_size, intermediate_size, bias=True, linear_method=linear_method) self.c_proj = RowParallelLinear(intermediate_size, hidden_size, bias=True, linear_method=linear_method) quant_config = getattr(linear_method, 'quant_config...
def __init__(self, intermediate_size: int, config: GPT2Config, linear_method: Optional[LinearMethodBase]=None): super().__init__() hidden_size = config.hidden_size self.c_fc = ColumnParallelLinear(hidden_size, intermediate_size, bias= True, linear_method=linear_method) self.c_proj = RowParal...
null
_preempt_by_recompute
seqs = seq_group.get_seqs(status=SequenceStatus.RUNNING) assert len(seqs) == 1 for seq in seqs: seq.status = SequenceStatus.WAITING self.block_manager.free(seq) self.waiting.insert(0, seq_group)
def _preempt_by_recompute(self, seq_group: SequenceGroup) ->None: seqs = seq_group.get_seqs(status=SequenceStatus.RUNNING) assert len(seqs) == 1 for seq in seqs: seq.status = SequenceStatus.WAITING self.block_manager.free(seq) self.waiting.insert(0, seq_group)
null
__init__
self.scaling_factor = scaling_factor self.extrapolation_factor = extrapolation_factor self.attn_factor = attn_factor self.beta_fast = beta_fast self.beta_slow = beta_slow self.mscale = float(_yarn_get_mscale(self.scaling_factor) * attn_factor) super().__init__(head_size, rotary_dim, max_position_embeddings, base, i...
def __init__(self, head_size: int, rotary_dim: int, max_position_embeddings: int, base: int, is_neox_style: bool, scaling_factor: float, *, extrapolation_factor: float=1, attn_factor: float=1, beta_fast: float= 32, beta_slow: float=1) ->None: self.scaling_factor = scaling_factor self.extrapolation_f...
null
__init__
super().__init__() self.config = config self.padding_idx = config.pad_token_id self.vocab_size = config.vocab_size self.embed_tokens = VocabParallelEmbedding(config.vocab_size, config. hidden_size) self.layers = nn.ModuleList([AquilaDecoderLayer(config, linear_method) for _ in range(config.num_hidden_layers)]) ...
def __init__(self, config: AquilaConfig, linear_method: Optional[ LinearMethodBase]=None): super().__init__() self.config = config self.padding_idx = config.pad_token_id self.vocab_size = config.vocab_size self.embed_tokens = VocabParallelEmbedding(config.vocab_size, config. hidden_size)...
null
__init__
super().__init__() self.config = config self.linear_method = linear_method self.model = AquilaModel(config, linear_method) self.lm_head = ParallelLMHead(config.vocab_size, config.hidden_size) self.sampler = Sampler(config.vocab_size)
def __init__(self, config, linear_method: Optional[LinearMethodBase]=None): super().__init__() self.config = config self.linear_method = linear_method self.model = AquilaModel(config, linear_method) self.lm_head = ParallelLMHead(config.vocab_size, config.hidden_size) self.sampler = Sampler(confi...
null
__eq__
if not isinstance(other, SequenceOutput): raise NotImplementedError() return self.parent_seq_id == other.parent_seq_id and self.output_token == other.output_token and self.logprobs == other.logprobs
def __eq__(self, other: object) ->bool: if not isinstance(other, SequenceOutput): raise NotImplementedError() return (self.parent_seq_id == other.parent_seq_id and self.output_token == other.output_token and self.logprobs == other.logprobs)
null
http_bot
headers = {'User-Agent': 'vLLM Client'} pload = {'prompt': prompt, 'stream': True, 'max_tokens': 128} response = requests.post(args.model_url, headers=headers, json=pload, stream=True) for chunk in response.iter_lines(chunk_size=8192, decode_unicode=False, delimiter=b'\x00'): if chunk: data = json.l...
def http_bot(prompt): headers = {'User-Agent': 'vLLM Client'} pload = {'prompt': prompt, 'stream': True, 'max_tokens': 128} response = requests.post(args.model_url, headers=headers, json=pload, stream=True) for chunk in response.iter_lines(chunk_size=8192, decode_unicode=False, delimiter...
null
load_weights
stacked_params_mapping = [('qkv_proj', 'q_proj', 'q'), ('qkv_proj', 'k_proj', 'k'), ('qkv_proj', 'v_proj', 'v'), ('gate_up_proj', 'gate_proj', 0), ('gate_up_proj', 'up_proj', 1)] params_dict = dict(self.named_parameters()) for name, loaded_weight in hf_model_weights_iterator(model_name_or_path, cache_dir, l...
def load_weights(self, model_name_or_path: str, cache_dir: Optional[str]= None, load_format: str='auto', revision: Optional[str]=None): stacked_params_mapping = [('qkv_proj', 'q_proj', 'q'), ('qkv_proj', 'k_proj', 'k'), ('qkv_proj', 'v_proj', 'v'), ('gate_up_proj', 'gate_proj', 0), ('gate_up_pro...
null
__init__
super().__init__() self.hidden_size = hidden_size tensor_model_parallel_world_size = get_tensor_model_parallel_world_size() self.total_num_heads = num_heads assert self.total_num_heads % tensor_model_parallel_world_size == 0 self.num_heads = self.total_num_heads // tensor_model_parallel_world_size self.head_dim = hidde...
def __init__(self, hidden_size: int, num_heads: int, bias: bool, rope_theta: float=10000, max_position_embeddings: int=8192, linear_method: Optional [LinearMethodBase]=None, rope_scaling: Optional[Dict[str, Any]]=None): super().__init__() self.hidden_size = hidden_size tensor_model_parallel_world_si...
null
__init__
super().__init__() self.num_experts = num_experts self.ffn_dim = intermediate_size self.hidden_dim = hidden_size self.w1 = ReplicatedLinear(self.hidden_dim, self.ffn_dim, bias=False, linear_method=linear_method) self.w2 = ReplicatedLinear(self.ffn_dim, self.hidden_dim, bias=False, linear_method=linear_method) s...
def __init__(self, num_experts: int, hidden_size: int, intermediate_size: int, linear_method: Optional[LinearMethodBase]=None) ->None: super().__init__() self.num_experts = num_experts self.ffn_dim = intermediate_size self.hidden_dim = hidden_size self.w1 = ReplicatedLinear(self.hidden_dim, self...
null
_allocate
self.block_manager.allocate(seq_group) for seq in seq_group.get_seqs(status=SequenceStatus.WAITING): seq.status = SequenceStatus.RUNNING
def _allocate(self, seq_group: SequenceGroup) ->None: self.block_manager.allocate(seq_group) for seq in seq_group.get_seqs(status=SequenceStatus.WAITING): seq.status = SequenceStatus.RUNNING
null
set_random_seed
random.seed(seed) np.random.seed(seed) torch.manual_seed(seed) if torch.cuda.is_available(): torch.cuda.manual_seed_all(seed)
def set_random_seed(seed: int) ->None: random.seed(seed) np.random.seed(seed) torch.manual_seed(seed) if torch.cuda.is_available(): torch.cuda.manual_seed_all(seed)
null
forward
qkv, _ = self.qkv_proj(hidden_states) q, k, v = qkv.split([self.q_size, self.kv_size, self.kv_size], dim=-1) q, k = self.rotary_emb(positions, q, k) k_cache, v_cache = kv_cache attn_output = self.attn(q, k, v, k_cache, v_cache, input_metadata) output, _ = self.o_proj(attn_output) return output
def forward(self, positions: torch.Tensor, hidden_states: torch.Tensor, kv_cache: KVCache, input_metadata: InputMetadata) ->torch.Tensor: qkv, _ = self.qkv_proj(hidden_states) q, k, v = qkv.split([self.q_size, self.kv_size, self.kv_size], dim=-1) q, k = self.rotary_emb(positions, q, k) k_cache, v_ca...
null
_check_stop
"""Stop the finished sequences.""" for stop_str in sampling_params.stop: if seq.output_text.endswith(stop_str): if not sampling_params.include_stop_str_in_output: seq.output_text = seq.output_text[:-len(stop_str)] seq.status = SequenceStatus.FINISHED_STOPPED return if seq.get_las...
def _check_stop(self, seq: Sequence, sampling_params: SamplingParams) ->None: """Stop the finished sequences.""" for stop_str in sampling_params.stop: if seq.output_text.endswith(stop_str): if not sampling_params.include_stop_str_in_output: seq.output_text = seq.output_text[:...
Stop the finished sequences.
__repr__
return f'CompletionOutput(index={self.index}, text={self.text!r}, token_ids={self.token_ids}, cumulative_logprob={self.cumulative_logprob}, logprobs={self.logprobs}, finish_reason={self.finish_reason})'
def __repr__(self) ->str: return ( f'CompletionOutput(index={self.index}, text={self.text!r}, token_ids={self.token_ids}, cumulative_logprob={self.cumulative_logprob}, logprobs={self.logprobs}, finish_reason={self.finish_reason})' )
null
create_weights
if input_size_per_partition % self.quant_config.pack_factor != 0: raise ValueError( 'The input size is not aligned with the quantized weight shape. This can be caused by too large tensor parallel size.' ) qweight = Parameter(torch.empty(input_size_per_partition // self. quant_config.pack_factor,...
def create_weights(self, input_size_per_partition: int, output_size_per_partition: int, input_size: int, output_size: int, params_dtype: torch.dtype) ->Dict[str, Any]: if input_size_per_partition % self.quant_config.pack_factor != 0: raise ValueError( 'The input size is not aligned with ...
null
forward
return super().forward(positions + self.offset)
def forward(self, positions: torch.Tensor): return super().forward(positions + self.offset)
null
__init__
super().__init__() self.config = config self.linear_method = linear_method self.transformer = GPTBigCodeModel(config, linear_method) self.lm_head_weight = self.transformer.wte.weight self.sampler = Sampler(config.vocab_size)
def __init__(self, config: GPTBigCodeConfig, linear_method: Optional[ LinearMethodBase]=None): super().__init__() self.config = config self.linear_method = linear_method self.transformer = GPTBigCodeModel(config, linear_method) self.lm_head_weight = self.transformer.wte.weight self.sampler =...
null
test_paged_attention
random.seed(seed) torch.random.manual_seed(seed) torch.cuda.manual_seed(seed) gpu_id = f'cuda:{device}' scale = float(1.0 / head_size ** 0.5) num_query_heads, num_kv_heads = num_heads query = torch.empty(num_seqs, num_query_heads, head_size, dtype=dtype, device=gpu_id) query.uniform_(-scale, scale) assert num_query...
@pytest.mark.parametrize('version', ['v1', 'v2']) @pytest.mark.parametrize('num_seqs', NUM_GEN_SEQS) @pytest.mark.parametrize('num_heads', NUM_HEADS) @pytest.mark.parametrize('head_size', HEAD_SIZES) @pytest.mark.parametrize('use_alibi', USE_ALIBI) @pytest.mark.parametrize('block_size', BLOCK_SIZES) @pytest.mark.parame...
null
__init__
self.n = n self.best_of = best_of if best_of is not None else n self.presence_penalty = presence_penalty self.frequency_penalty = frequency_penalty self.repetition_penalty = repetition_penalty self.temperature = temperature self.top_p = top_p self.top_k = top_k self.min_p = min_p self.use_beam_search = use_beam_search ...
def __init__(self, n: int=1, best_of: Optional[int]=None, presence_penalty: float=0.0, frequency_penalty: float=0.0, repetition_penalty: float=1.0, temperature: float=1.0, top_p: float=1.0, top_k: int=-1, min_p: float= 0.0, use_beam_search: bool=False, length_penalty: float=1.0, early_stopping: Union[bo...
null
_apply_top_p_top_k
logits_sort, logits_idx = logits.sort(dim=-1, descending=True) probs_sort = logits_sort.softmax(dim=-1) probs_sum = probs_sort.cumsum(dim=-1).sub_(probs_sort) top_p_mask = probs_sum > p.unsqueeze_(dim=1) top_k_mask = torch.arange(logits_idx.shape[-1], device=logits_idx.device) top_k_mask = top_k_mask.expand(logits_idx....
def _apply_top_p_top_k(logits: torch.Tensor, p: torch.Tensor, k: torch.Tensor ) ->torch.Tensor: logits_sort, logits_idx = logits.sort(dim=-1, descending=True) probs_sort = logits_sort.softmax(dim=-1) probs_sum = probs_sort.cumsum(dim=-1).sub_(probs_sort) top_p_mask = probs_sum > p.unsqueeze_(dim=1) ...
null
__init__
self.weight_bits = weight_bits if self.weight_bits != 4: raise ValueError( f'Currently, only 4-bit weight quantization is supported for SqueezeLLM, but got {self.weight_bits} bits.' ) self.pack_factor = 32 // self.weight_bits
def __init__(self, weight_bits: int) ->None: self.weight_bits = weight_bits if self.weight_bits != 4: raise ValueError( f'Currently, only 4-bit weight quantization is supported for SqueezeLLM, but got {self.weight_bits} bits.' ) self.pack_factor = 32 // self.weight_bits
null
api_server
script_path = Path(__file__).parent.joinpath('api_server_async_engine.py' ).absolute() uvicorn_process = subprocess.Popen([sys.executable, '-u', str(script_path), '--model', 'facebook/opt-125m']) yield uvicorn_process.terminate()
@pytest.fixture def api_server(): script_path = Path(__file__).parent.joinpath('api_server_async_engine.py' ).absolute() uvicorn_process = subprocess.Popen([sys.executable, '-u', str( script_path), '--model', 'facebook/opt-125m']) yield uvicorn_process.terminate()
null
set_cuda_visible_devices
os.environ['CUDA_VISIBLE_DEVICES'] = ','.join(map(str, device_ids))
def set_cuda_visible_devices(device_ids: List[int]) ->None: os.environ['CUDA_VISIBLE_DEVICES'] = ','.join(map(str, device_ids))
null
test_no_load_chat_template
template = '../../examples/does_not_exist' mock_args = Namespace(chat_template=template) tokenizer = MockTokenizer() load_chat_template(mock_args, tokenizer=tokenizer) template_content = tokenizer.chat_template assert template_content is not None assert template_content == '../../examples/does_not_exist'
def test_no_load_chat_template(): template = '../../examples/does_not_exist' mock_args = Namespace(chat_template=template) tokenizer = MockTokenizer() load_chat_template(mock_args, tokenizer=tokenizer) template_content = tokenizer.chat_template assert template_content is not None assert temp...
null
forward
return self.wte(input_ids)
def forward(self, input_ids: torch.LongTensor): return self.wte(input_ids)
null
__init__
self.scaling_factor = scaling_factor super().__init__(head_size, rotary_dim, max_position_embeddings, base, is_neox_style)
def __init__(self, head_size: int, rotary_dim: int, max_position_embeddings: int, base: int, is_neox_style: bool, scaling_factor: float) ->None: self.scaling_factor = scaling_factor super().__init__(head_size, rotary_dim, max_position_embeddings, base, is_neox_style)
null
__init__
super().__init__() self.add_bias = config.add_bias_linear self.dense_h_to_4h = MergedColumnParallelLinear(config.hidden_size, [config .ffn_hidden_size] * 2, bias=config.add_bias_linear, linear_method= linear_method) self.activation_func = SiluAndMul() self.dense_4h_to_h = RowParallelLinear(config.ffn_hidden_siz...
def __init__(self, config, linear_method: Optional[LinearMethodBase]=None): super().__init__() self.add_bias = config.add_bias_linear self.dense_h_to_4h = MergedColumnParallelLinear(config.hidden_size, [ config.ffn_hidden_size] * 2, bias=config.add_bias_linear, linear_method=linear_method) ...
null
_forward
"""PyTorch-native implementation equivalent to forward().""" return 0.5 * x * (1.0 + torch.tanh(x * 0.7978845608 * (1.0 + 0.044715 * x * x)) )
def _forward(self, x: torch.Tensor) ->torch.Tensor: """PyTorch-native implementation equivalent to forward().""" return 0.5 * x * (1.0 + torch.tanh(x * 0.7978845608 * (1.0 + 0.044715 * x * x)))
PyTorch-native implementation equivalent to forward().
__init__
super().__init__() self.ln = nn.LayerNorm(config.hidden_size, eps=config.layer_norm_epsilon) self.linear = ParallelLMHead(config.vocab_size, config.hidden_size, bias=True)
def __init__(self, config: PretrainedConfig): super().__init__() self.ln = nn.LayerNorm(config.hidden_size, eps=config.layer_norm_epsilon) self.linear = ParallelLMHead(config.vocab_size, config.hidden_size, bias=True)
null
_validate_config
self.attn_config = self._set_config_defaults(self.attn_config, attn_config_defaults) self.ffn_config = self._set_config_defaults(self.ffn_config, ffn_config_defaults) self.init_config = self._set_config_defaults(self.init_config, init_config_defaults) if self.d_model % self.n_heads != 0: raise ValueErro...
def _validate_config(self) ->None: self.attn_config = self._set_config_defaults(self.attn_config, attn_config_defaults) self.ffn_config = self._set_config_defaults(self.ffn_config, ffn_config_defaults) self.init_config = self._set_config_defaults(self.init_config, init_config_default...
null
get_output_len
return len(self.output_token_ids)
def get_output_len(self) ->int: return len(self.output_token_ids)
null
get_scaled_act_names
return []
def get_scaled_act_names(self) ->List[str]: return []
null
load_weights
params_dict = dict(self.named_parameters(remove_duplicate=False)) for name, loaded_weight in hf_model_weights_iterator(model_name_or_path, cache_dir, load_format, revision): if 'lm_head.weight' in name: continue if '.attn.bias' in name: continue param = params_dict[name] weight_loade...
def load_weights(self, model_name_or_path: str, cache_dir: Optional[str]= None, load_format: str='auto', revision: Optional[str]=None): params_dict = dict(self.named_parameters(remove_duplicate=False)) for name, loaded_weight in hf_model_weights_iterator(model_name_or_path, cache_dir, load_format, r...
null
get_vocab_size
return self.hf_config.vocab_size
def get_vocab_size(self) ->int: return self.hf_config.vocab_size
null
can_allocate
seq = seq_group.get_seqs(status=SequenceStatus.WAITING)[0] num_required_blocks = len(seq.logical_token_blocks) if self.block_sliding_window is not None: num_required_blocks = min(num_required_blocks, self.block_sliding_window) num_free_gpu_blocks = self.gpu_allocator.get_num_free_blocks() if self.num_total_gpu_bloc...
def can_allocate(self, seq_group: SequenceGroup) ->AllocStatus: seq = seq_group.get_seqs(status=SequenceStatus.WAITING)[0] num_required_blocks = len(seq.logical_token_blocks) if self.block_sliding_window is not None: num_required_blocks = min(num_required_blocks, self. block_sliding_wind...
null
forward
del position_ids qkv, _ = self.query_key_value(hidden_states) q, k, v = qkv.chunk(chunks=3, dim=-1) k_cache, v_cache = kv_cache attn_output = self.attn(q, k, v, k_cache, v_cache, input_metadata) output, _ = self.dense(attn_output) return output
def forward(self, position_ids: torch.Tensor, hidden_states: torch.Tensor, kv_cache: KVCache, input_metadata: InputMetadata) ->torch.Tensor: del position_ids qkv, _ = self.query_key_value(hidden_states) q, k, v = qkv.chunk(chunks=3, dim=-1) k_cache, v_cache = kv_cache attn_output = self.attn(q, ...
null
_prepare_test
vocab_size = 32000 input_tensor = torch.rand((batch_size, 1024), device='cuda', dtype=torch. float16) fake_logits = torch.full((batch_size, vocab_size), 0.01, device= input_tensor.device, dtype=input_tensor.dtype) sampler = MockLogitsSampler(32000, fake_logits) model_runner = ModelRunner(None, None, None) retur...
def _prepare_test(batch_size: int) ->Tuple[torch.Tensor, torch.Tensor, MockLogitsSampler, ModelRunner]: vocab_size = 32000 input_tensor = torch.rand((batch_size, 1024), device='cuda', dtype= torch.float16) fake_logits = torch.full((batch_size, vocab_size), 0.01, device= input_tensor.devi...
null
__repr__
return f'SequenceGroupOutput(samples={self.samples}, prompt_logprobs={self.prompt_logprobs})'
def __repr__(self) ->str: return ( f'SequenceGroupOutput(samples={self.samples}, prompt_logprobs={self.prompt_logprobs})' )
null
get_node_ip
return get_ip()
def get_node_ip(self) ->str: return get_ip()
null
get_supported_act_dtypes
"""List of supported activation dtypes.""" raise NotImplementedError
@abstractmethod def get_supported_act_dtypes(self) ->List[torch.dtype]: """List of supported activation dtypes.""" raise NotImplementedError
List of supported activation dtypes.
sample
next_tokens = self.sampler(self.lm_head.weight, hidden_states, sampling_metadata) return next_tokens
def sample(self, hidden_states: torch.Tensor, sampling_metadata: SamplingMetadata) ->Optional[SamplerOutput]: next_tokens = self.sampler(self.lm_head.weight, hidden_states, sampling_metadata) return next_tokens
null
forward
inputs_embeds = self.wte(input_ids) position_embeds = self.wpe(position_ids) hidden_states = inputs_embeds + position_embeds for i in range(len(self.h)): layer = self.h[i] hidden_states = layer(hidden_states, kv_caches[i], input_metadata) hidden_states = self.ln_f(hidden_states) return hidden_states
def forward(self, input_ids: torch.Tensor, position_ids: torch.Tensor, kv_caches: List[KVCache], input_metadata: InputMetadata) ->torch.Tensor: inputs_embeds = self.wte(input_ids) position_embeds = self.wpe(position_ids) hidden_states = inputs_embeds + position_embeds for i in range(len(self.h)): ...
null
__getstate__
state = self.__dict__.copy() state['sp_model'] = None return state
def __getstate__(self): state = self.__dict__.copy() state['sp_model'] = None return state
null
create_engine_configs
model_config = ModelConfig(self.model, self.tokenizer, self.tokenizer_mode, self.trust_remote_code, self.download_dir, self.load_format, self.dtype, self.seed, self.revision, self.tokenizer_revision, self.max_model_len, self.quantization, self.enforce_eager, self.max_context_len_to_capture) cache_config = C...
def create_engine_configs(self) ->Tuple[ModelConfig, CacheConfig, ParallelConfig, SchedulerConfig]: model_config = ModelConfig(self.model, self.tokenizer, self. tokenizer_mode, self.trust_remote_code, self.download_dir, self. load_format, self.dtype, self.seed, self.revision, self. token...
null
_run_incremental_decode
decoded_text = '' offset = 0 token_offset = 0 prev_tokens = None for i in range(len(all_input_ids)): new_tokens, text, offset, token_offset = detokenize_incrementally(tokenizer , all_input_ids[:i + 1], prev_tokens, offset, token_offset, skip_special_tokens=skip_special_tokens) decoded_text += te...
def _run_incremental_decode(tokenizer, all_input_ids, skip_special_tokens: bool ): decoded_text = '' offset = 0 token_offset = 0 prev_tokens = None for i in range(len(all_input_ids)): new_tokens, text, offset, token_offset = detokenize_incrementally( tokenizer, all_input_ids[...
null
__init__
self.offset = 2 super().__init__(num_embeddings + self.offset, embedding_dim)
def __init__(self, num_embeddings: int, embedding_dim: int): self.offset = 2 super().__init__(num_embeddings + self.offset, embedding_dim)
null
__init__
super().__init__() self.config = config self.linear_method = linear_method self.transformer = FalconModel(config, linear_method) self.lm_head = ParallelLMHead(config.vocab_size, config.hidden_size) self.sampler = Sampler(config.vocab_size)
def __init__(self, config: FalconConfig, linear_method: Optional[ LinearMethodBase]=None): super().__init__() self.config = config self.linear_method = linear_method self.transformer = FalconModel(config, linear_method) self.lm_head = ParallelLMHead(config.vocab_size, config.hidden_size) sel...
null
load_weights
stacked_params_mapping = [('qkv_proj', 'q_proj', 'q'), ('qkv_proj', 'k_proj', 'k'), ('qkv_proj', 'v_proj', 'v'), ('gate_up_proj', 'gate_proj', 0), ('gate_up_proj', 'up_proj', 1)] params_dict = dict(self.named_parameters()) for name, loaded_weight in hf_model_weights_iterator(model_name_or_path, cache_dir, l...
def load_weights(self, model_name_or_path: str, cache_dir: Optional[str]= None, load_format: str='auto', revision: Optional[str]=None): stacked_params_mapping = [('qkv_proj', 'q_proj', 'q'), ('qkv_proj', 'k_proj', 'k'), ('qkv_proj', 'v_proj', 'v'), ('gate_up_proj', 'gate_proj', 0), ('gate_up_pro...
null
test_rms_norm
torch.random.manual_seed(seed) torch.cuda.manual_seed(seed) gpu_id = f'cuda:{device}' layer = RMSNorm(hidden_size).to(dtype=dtype, device=gpu_id) layer.weight.data.normal_(mean=1.0, std=0.1) scale = 1 / (2 * hidden_size) x = torch.randn(num_tokens, hidden_size, dtype=dtype, device=gpu_id) x *= scale residual = torch.ra...
@pytest.mark.parametrize('num_tokens', NUM_TOKENS) @pytest.mark.parametrize('hidden_size', HIDDEN_SIZES) @pytest.mark.parametrize('add_residual', ADD_RESIDUAL) @pytest.mark.parametrize('dtype', DTYPES) @pytest.mark.parametrize('seed', SEEDS) @pytest.mark.parametrize('device', DEVICES) @torch.inference_mode() def test_r...
null
_shared_pointers
ptrs = defaultdict(list) for k, v in tensors.items(): ptrs[v.data_ptr()].append(k) failing = [] for _, names in ptrs.items(): if len(names) > 1: failing.append(names) return failing
def _shared_pointers(tensors): ptrs = defaultdict(list) for k, v in tensors.items(): ptrs[v.data_ptr()].append(k) failing = [] for _, names in ptrs.items(): if len(names) > 1: failing.append(names) return failing
null
forward
hidden_states = self.transformer(input_ids, positions, kv_caches, input_metadata) return hidden_states
def forward(self, input_ids: torch.Tensor, positions: torch.Tensor, kv_caches: List[KVCache], input_metadata: InputMetadata) ->torch.Tensor: hidden_states = self.transformer(input_ids, positions, kv_caches, input_metadata) return hidden_states
null
get_linear_method
return GPTQLinearMethod(self)
def get_linear_method(self) ->'GPTQLinearMethod': return GPTQLinearMethod(self)
null
__init__
self.seq_groups = seq_groups self.seq_data = seq_data self.prompt_lens = prompt_lens self.selected_token_indices = selected_token_indices self.categorized_sample_indices = categorized_sample_indices self.perform_sampling = perform_sampling self.num_prompts = len(prompt_lens) if prompt_lens is not None else 0
def __init__(self, seq_groups: Optional[List[Tuple[List[int], SamplingParams]]], seq_data: Optional[Dict[int, SequenceData]], prompt_lens: Optional[List[int]], selected_token_indices: torch.Tensor, categorized_sample_indices: Optional[Dict[SamplingType, torch.Tensor]], perform_sampling: bool=True) ->Non...
null
__init__
self.model = model self.graph = None self.input_buffers: Dict[str, torch.Tensor] = {} self.output_buffers: Dict[str, torch.Tensor] = {}
def __init__(self, model: nn.Module): self.model = model self.graph = None self.input_buffers: Dict[str, torch.Tensor] = {} self.output_buffers: Dict[str, torch.Tensor] = {}
null
__init__
super().__init__() self.decoder = OPTDecoder(config, linear_method)
def __init__(self, config: OPTConfig, linear_method: Optional[ LinearMethodBase]=None): super().__init__() self.decoder = OPTDecoder(config, linear_method)
null
from_engine_args
"""Creates an async LLM engine from the engine arguments.""" engine_configs = engine_args.create_engine_configs() parallel_config = engine_configs[2] placement_group = initialize_cluster(parallel_config, engine_args. engine_use_ray) engine = cls(parallel_config.worker_use_ray, engine_args.engine_use_ray, * engi...
@classmethod def from_engine_args(cls, engine_args: AsyncEngineArgs, start_engine_loop: bool=True) ->'AsyncLLMEngine': """Creates an async LLM engine from the engine arguments.""" engine_configs = engine_args.create_engine_configs() parallel_config = engine_configs[2] placement_group = initialize_cl...
Creates an async LLM engine from the engine arguments.
forward
hidden_states = self.wte(input_ids) for i in range(len(self.blocks)): block = self.blocks[i] hidden_states = block(position_ids, hidden_states, kv_caches[i], input_metadata) hidden_states = self.norm_f(hidden_states) return hidden_states
def forward(self, input_ids: torch.Tensor, position_ids: torch.Tensor, kv_caches: List[KVCache], input_metadata: InputMetadata) ->torch.Tensor: hidden_states = self.wte(input_ids) for i in range(len(self.blocks)): block = self.blocks[i] hidden_states = block(position_ids, hidden_states, kv_c...
null
_swap_in
mapping = self.block_manager.swap_in(seq_group) blocks_to_swap_in.update(mapping) for seq in seq_group.get_seqs(status=SequenceStatus.SWAPPED): seq.status = SequenceStatus.RUNNING
def _swap_in(self, seq_group: SequenceGroup, blocks_to_swap_in: Dict[int, int] ) ->None: mapping = self.block_manager.swap_in(seq_group) blocks_to_swap_in.update(mapping) for seq in seq_group.get_seqs(status=SequenceStatus.SWAPPED): seq.status = SequenceStatus.RUNNING
null
_get_alibi_slopes
closest_power_of_2 = 2 ** math.floor(math.log2(total_num_heads)) base = torch.tensor(2 ** -2 ** -(math.log2(closest_power_of_2) - 3), dtype= torch.float32) powers = torch.arange(1, 1 + closest_power_of_2, dtype=torch.int32) slopes = torch.pow(base, powers) if closest_power_of_2 != total_num_heads: extra_base = ...
def _get_alibi_slopes(total_num_heads: int) ->torch.Tensor: closest_power_of_2 = 2 ** math.floor(math.log2(total_num_heads)) base = torch.tensor(2 ** -2 ** -(math.log2(closest_power_of_2) - 3), dtype=torch.float32) powers = torch.arange(1, 1 + closest_power_of_2, dtype=torch.int32) slopes = torc...
null
_verify_tokenizer_mode
tokenizer_mode = self.tokenizer_mode.lower() if tokenizer_mode not in ['auto', 'slow']: raise ValueError( f"Unknown tokenizer mode: {self.tokenizer_mode}. Must be either 'auto' or 'slow'." ) self.tokenizer_mode = tokenizer_mode
def _verify_tokenizer_mode(self) ->None: tokenizer_mode = self.tokenizer_mode.lower() if tokenizer_mode not in ['auto', 'slow']: raise ValueError( f"Unknown tokenizer mode: {self.tokenizer_mode}. Must be either 'auto' or 'slow'." ) self.tokenizer_mode = tokenizer_mode
null
get_num_free_cpu_blocks
return self.cpu_allocator.get_num_free_blocks()
def get_num_free_cpu_blocks(self) ->int: return self.cpu_allocator.get_num_free_blocks()
null
broadcast_object_list
"""Broadcast the input object list.""" world_size = torch.distributed.get_world_size() assert 0 <= src < world_size, f'Invalid src rank ({src})' if world_size == 1: return obj_list torch.distributed.broadcast_object_list(obj_list, src=src) return obj_list
def broadcast_object_list(obj_list, src=0): """Broadcast the input object list.""" world_size = torch.distributed.get_world_size() assert 0 <= src < world_size, f'Invalid src rank ({src})' if world_size == 1: return obj_list torch.distributed.broadcast_object_list(obj_list, src=src) retu...
Broadcast the input object list.
get_len
return len(self.output_token_ids) + len(self.prompt_token_ids)
def get_len(self) ->int: return len(self.output_token_ids) + len(self.prompt_token_ids)
null
init_worker
self.worker = worker_init_fn()
def init_worker(self, worker_init_fn): self.worker = worker_init_fn()
null
get_min_capability
return 75
def get_min_capability(self) ->int: return 75
null
__init__
super().__init__() self.config = config self.embed_dim = config.hidden_size self.self_attn = OPTAttention(embed_dim=self.embed_dim, num_heads=config. num_attention_heads, bias=config.enable_bias, linear_method=linear_method) self.do_layer_norm_before = config.do_layer_norm_before self.self_attn_layer_norm = nn.Laye...
def __init__(self, config: OPTConfig, linear_method: Optional[ LinearMethodBase]=None): super().__init__() self.config = config self.embed_dim = config.hidden_size self.self_attn = OPTAttention(embed_dim=self.embed_dim, num_heads= config.num_attention_heads, bias=config.enable_bias, linear_m...
null
forward
hidden_states = self.embd(input_ids) for i in range(self.config.num_hidden_layers): layer = self.h[i] hidden_states = layer(positions, hidden_states, kv_caches[i], input_metadata) return hidden_states
def forward(self, input_ids: torch.Tensor, positions: torch.Tensor, kv_caches: List[KVCache], input_metadata: InputMetadata) ->torch.Tensor: hidden_states = self.embd(input_ids) for i in range(self.config.num_hidden_layers): layer = self.h[i] hidden_states = layer(positions, hidden_states, k...
null
test_models
hf_model = hf_runner(model, dtype=dtype) hf_outputs = hf_model.generate_greedy(example_prompts, max_tokens) del hf_model vllm_model = vllm_runner(model, dtype=dtype) vllm_outputs = vllm_model.generate_greedy(example_prompts, max_tokens) del vllm_model for i in range(len(example_prompts)): hf_output_ids, hf_output_s...
@pytest.mark.parametrize('model', MODELS) @pytest.mark.parametrize('dtype', ['float']) @pytest.mark.parametrize('max_tokens', [128]) def test_models(hf_runner, vllm_runner, example_prompts, model: str, dtype: str, max_tokens: int) ->None: hf_model = hf_runner(model, dtype=dtype) hf_outputs = hf_model.genera...
null
forward
if self.tp_size > 1: input_mask = (input_ < self.vocab_start_index) | (input_ >= self. vocab_end_index) masked_input = input_.clone() - self.vocab_start_index masked_input[input_mask] = 0 else: masked_input = input_ output_parallel = F.embedding(masked_input, self.weight) if self.tp_size > 1: ...
def forward(self, input_): if self.tp_size > 1: input_mask = (input_ < self.vocab_start_index) | (input_ >= self. vocab_end_index) masked_input = input_.clone() - self.vocab_start_index masked_input[input_mask] = 0 else: masked_input = input_ output_parallel = F.e...
null
get_seqs
if status is None: return list(self.seqs_dict.values()) else: return [seq for seq in self.seqs_dict.values() if seq.status == status]
def get_seqs(self, status: Optional[SequenceStatus]=None) ->List[Sequence]: if status is None: return list(self.seqs_dict.values()) else: return [seq for seq in self.seqs_dict.values() if seq.status == status]
null
execute_model
input_tokens, input_positions, input_metadata, sampling_metadata = (self. prepare_input_tensors(seq_group_metadata_list)) if input_metadata.use_cuda_graph: graph_batch_size = input_tokens.shape[0] model_executable = self.graph_runners[graph_batch_size] else: model_executable = self.model hidden_states =...
@torch.inference_mode() def execute_model(self, seq_group_metadata_list: Optional[List[ SequenceGroupMetadata]], kv_caches: List[Tuple[torch.Tensor, torch.Tensor]] ) ->Optional[SamplerOutput]: input_tokens, input_positions, input_metadata, sampling_metadata = (self .prepare_input_tensors(seq_group_m...
null
ensure_divisibility
"""Ensure that numerator is divisible by the denominator.""" assert numerator % denominator == 0, '{} is not divisible by {}'.format( numerator, denominator)
def ensure_divisibility(numerator, denominator): """Ensure that numerator is divisible by the denominator.""" assert numerator % denominator == 0, '{} is not divisible by {}'.format( numerator, denominator)
Ensure that numerator is divisible by the denominator.
forward
residual = hidden_states hidden_states = self.ln_1(hidden_states) attn_output = self.attn(hidden_states=hidden_states, kv_cache=kv_cache, input_metadata=input_metadata) hidden_states = attn_output + residual residual = hidden_states hidden_states = self.ln_2(hidden_states) feed_forward_hidden_states = self.mlp(hidd...
def forward(self, hidden_states: torch.Tensor, kv_cache: KVCache, input_metadata: InputMetadata) ->torch.Tensor: residual = hidden_states hidden_states = self.ln_1(hidden_states) attn_output = self.attn(hidden_states=hidden_states, kv_cache=kv_cache, input_metadata=input_metadata) hidden_sta...
null
__init__
super().__init__() self.padding_idx = config.pad_token_id self.vocab_size = config.vocab_size self.embed_tokens = VocabParallelEmbedding(config.vocab_size, config. hidden_size) self.layers = nn.ModuleList([MixtralDecoderLayer(config, linear_method= linear_method) for _ in range(config.num_hidden_layers)]) self....
def __init__(self, config: MixtralConfig, linear_method: Optional[ LinearMethodBase]=None) ->None: super().__init__() self.padding_idx = config.pad_token_id self.vocab_size = config.vocab_size self.embed_tokens = VocabParallelEmbedding(config.vocab_size, config. hidden_size) self.layers ...
null
swap_out
mapping: Dict[PhysicalTokenBlock, PhysicalTokenBlock] = {} for seq in seq_group.get_seqs(status=SequenceStatus.RUNNING): new_block_table: BlockTable = [] block_table = self.block_tables[seq.seq_id] for gpu_block in block_table: if gpu_block in mapping: cpu_block = mapping[gpu_block] ...
def swap_out(self, seq_group: SequenceGroup) ->Dict[int, int]: mapping: Dict[PhysicalTokenBlock, PhysicalTokenBlock] = {} for seq in seq_group.get_seqs(status=SequenceStatus.RUNNING): new_block_table: BlockTable = [] block_table = self.block_tables[seq.seq_id] for gpu_block in block_tabl...
null
__init__
super().__init__() self.act = act_module self.input_is_parallel = input_is_parallel if input_is_parallel: tp_size = get_tensor_model_parallel_world_size() intermediate_size_per_partition = divide(intermediate_size, tp_size) else: intermediate_size_per_partition = intermediate_size if params_dtype is None: ...
def __init__(self, act_module: nn.Module, intermediate_size: int, input_is_parallel: bool=True, params_dtype: Optional[torch.dtype]=None): super().__init__() self.act = act_module self.input_is_parallel = input_is_parallel if input_is_parallel: tp_size = get_tensor_model_parallel_world_size(...
null