method_name stringlengths 3 45 | method_body stringlengths 9 6.25k | full_code stringlengths 35 7.02k | docstring stringlengths 18 4.7k ⌀ |
|---|---|---|---|
__init__ | self.quant_config = quant_config | def __init__(self, quant_config: GPTQConfig):
self.quant_config = quant_config | null |
__init__ | super().__init__()
n_inner = getattr(config, 'n_inner', None)
n_inner = n_inner if n_inner is not None else 4 * config.hidden_size
self.fc1 = ColumnParallelLinear(config.hidden_size, n_inner, linear_method=
linear_method)
self.fc2 = RowParallelLinear(n_inner, config.hidden_size, linear_method=
linear_method)
qu... | def __init__(self, config: PretrainedConfig, linear_method: Optional[
LinearMethodBase]=None):
super().__init__()
n_inner = getattr(config, 'n_inner', None)
n_inner = n_inner if n_inner is not None else 4 * config.hidden_size
self.fc1 = ColumnParallelLinear(config.hidden_size, n_inner,
linea... | null |
is_finished | return status in [SequenceStatus.FINISHED_STOPPED, SequenceStatus.
FINISHED_LENGTH_CAPPED, SequenceStatus.FINISHED_ABORTED, SequenceStatus
.FINISHED_IGNORED] | @staticmethod
def is_finished(status: 'SequenceStatus') ->bool:
return status in [SequenceStatus.FINISHED_STOPPED, SequenceStatus.
FINISHED_LENGTH_CAPPED, SequenceStatus.FINISHED_ABORTED,
SequenceStatus.FINISHED_IGNORED] | null |
_abort | """Abort a request.
Abort a submitted request. If the request is finished or not found,
this method will be a no-op.
Args:
request_id: The unique id of the request.
"""
self._request_tracker.abort_request(request_id, verbose=self.log_requests) | def _abort(self, request_id: str) ->None:
"""Abort a request.
Abort a submitted request. If the request is finished or not found,
this method will be a no-op.
Args:
request_id: The unique id of the request.
"""
self._request_tracker.abort_request(request_id, verbose... | Abort a request.
Abort a submitted request. If the request is finished or not found,
this method will be a no-op.
Args:
request_id: The unique id of the request. |
_query_server | response = requests.post('http://localhost:8000/generate', json={'prompt':
prompt, 'max_tokens': max_tokens, 'temperature': 0, 'ignore_eos': True})
response.raise_for_status()
return response.json() | def _query_server(prompt: str, max_tokens: int=5) ->dict:
response = requests.post('http://localhost:8000/generate', json={
'prompt': prompt, 'max_tokens': max_tokens, 'temperature': 0,
'ignore_eos': True})
response.raise_for_status()
return response.json() | null |
from_lists | pin_memory = not in_wsl()
prompt_max_len = max(len(tokens) for tokens in prompt_tokens)
prompt_padded_tokens = [(tokens + [vocab_size] * (prompt_max_len - len(
tokens))) for tokens in prompt_tokens]
output_max_len = max(len(tokens) for tokens in output_tokens)
output_padded_tokens = [(tokens + [vocab_size] * (outpu... | @classmethod
def from_lists(cls, temperatures: List[float], top_ps: List[float], top_ks:
List[int], min_ps: List[float], presence_penalties: List[float],
frequency_penalties: List[float], repetition_penalties: List[float],
prompt_tokens: List[List[int]], output_tokens: List[List[int]],
vocab_size: int, ... | null |
test_sampler_mixed | set_random_seed(seed)
batch_size = random.randint(1, 256)
input_tensor, fake_logits, sampler, model_runner = _prepare_test(batch_size)
seq_group_metadata_list = []
expected_tokens = []
prompt_lens = []
for i in range(batch_size):
n = 1
sampling_type = random.randint(0, 2)
if sampling_type == 0:
samp... | @pytest.mark.parametrize('seed', RANDOM_SEEDS)
def test_sampler_mixed(seed: int):
set_random_seed(seed)
batch_size = random.randint(1, 256)
input_tensor, fake_logits, sampler, model_runner = _prepare_test(batch_size
)
seq_group_metadata_list = []
expected_tokens = []
prompt_lens = []
... | null |
forward | hidden_states = self.model(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.model(input_ids, positions, kv_caches, input_metadata)
return hidden_states | null |
__init__ | super().__init__()
inner_dim = 4 * config.n_embd if config.n_inner is None else config.n_inner
self.ln_1 = nn.LayerNorm(config.n_embd, eps=config.layer_norm_epsilon)
self.attn = GPTJAttention(config, linear_method)
self.mlp = GPTJMLP(inner_dim, config, linear_method) | def __init__(self, config: GPTJConfig, linear_method: Optional[
LinearMethodBase]=None):
super().__init__()
inner_dim = 4 * config.n_embd if config.n_inner is None else config.n_inner
self.ln_1 = nn.LayerNorm(config.n_embd, eps=config.layer_norm_epsilon)
self.attn = GPTJAttention(config, linear_meth... | null |
get_rope | key = head_size, rotary_dim, max_position, base, is_neox_style, tuple(
rope_scaling.items()) if rope_scaling is not None else None
if key in _ROPE_DICT:
return _ROPE_DICT[key]
if rope_scaling is None:
rotary_emb = RotaryEmbedding(head_size, rotary_dim, max_position, base,
is_neox_style)
else:
sc... | def get_rope(head_size: int, rotary_dim: int, max_position: int, base: int,
is_neox_style: bool=True, rope_scaling: Optional[Dict[str, Any]]=None
) ->RotaryEmbedding:
key = head_size, rotary_dim, max_position, base, is_neox_style, tuple(
rope_scaling.items()) if rope_scaling is not None else None
... | null |
_run_workers | """Runs the given method on all workers."""
if max_concurrent_workers:
raise NotImplementedError('max_concurrent_workers is not supported yet.')
ray_worker_outputs = [worker.execute_method.remote(method, *args, **kwargs) for
worker in self.workers]
if driver_args is None:
driver_args = args
if driver_kwargs... | def _run_workers(self, method: str, *args, driver_args: Optional[List[Any]]
=None, driver_kwargs: Optional[Dict[str, Any]]=None,
max_concurrent_workers: Optional[int]=None, **kwargs) ->Any:
"""Runs the given method on all workers."""
if max_concurrent_workers:
raise NotImplementedError(
... | Runs the given method on all workers. |
_forward | """PyTorch-native implementation equivalent to forward()."""
query = query.view(*query.shape[:-1], -1, self.head_size)
key = key.view(*key.shape[:-1], -1, self.head_size)
query_rot = query[..., :self.rotary_dim]
key_rot = key[..., :self.rotary_dim]
if self.rotary_dim < self.head_size:
query_pass = query[..., self.r... | def _forward(self, positions: torch.Tensor, query: torch.Tensor, key: torch
.Tensor) ->Tuple[torch.Tensor, torch.Tensor]:
"""PyTorch-native implementation equivalent to forward()."""
query = query.view(*query.shape[:-1], -1, self.head_size)
key = key.view(*key.shape[:-1], -1, self.head_size)
query_r... | PyTorch-native implementation equivalent to forward(). |
__aiter__ | return self | def __aiter__(self):
return self | null |
process_request_output | """Process a request output from the engine."""
request_id = request_output.request_id
self._request_streams[request_id].put(request_output)
if request_output.finished:
if verbose:
logger.info(f'Finished request {request_id}.')
self.abort_request(request_id) | def process_request_output(self, request_output: RequestOutput, *, verbose:
bool=False) ->None:
"""Process a request output from the engine."""
request_id = request_output.request_id
self._request_streams[request_id].put(request_output)
if request_output.finished:
if verbose:
log... | Process a request output from the engine. |
__repr__ | return f'SequenceData(prompt_token_ids={self.prompt_token_ids}, output_token_ids={self.output_token_ids}, cumulative_logprob={self.cumulative_logprob})' | def __repr__(self) ->str:
return (
f'SequenceData(prompt_token_ids={self.prompt_token_ids}, output_token_ids={self.output_token_ids}, cumulative_logprob={self.cumulative_logprob})'
) | null |
sampling_type | if self.use_beam_search:
return SamplingType.BEAM
if self.temperature < _SAMPLING_EPS:
return SamplingType.GREEDY
return SamplingType.RANDOM | @cached_property
def sampling_type(self) ->SamplingType:
if self.use_beam_search:
return SamplingType.BEAM
if self.temperature < _SAMPLING_EPS:
return SamplingType.GREEDY
return SamplingType.RANDOM | null |
forward | d = x.shape[-1] // 2
output_shape = x.shape[:-1] + (d,)
out = torch.empty(output_shape, dtype=x.dtype, device=x.device)
ops.silu_and_mul(out, x)
return out | def forward(self, x: torch.Tensor) ->torch.Tensor:
d = x.shape[-1] // 2
output_shape = x.shape[:-1] + (d,)
out = torch.empty(output_shape, dtype=x.dtype, device=x.device)
ops.silu_and_mul(out, x)
return out | 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 |
prompt | return next(iter(self.seqs_dict.values())).prompt | @property
def prompt(self) ->str:
return next(iter(self.seqs_dict.values())).prompt | null |
__init__ | super().__init__()
self.num_embeddings = num_embeddings
self.num_embeddings_padded = pad_vocab_size(num_embeddings)
self.embedding_dim = embedding_dim
if params_dtype is None:
params_dtype = torch.get_default_dtype()
self.tp_size = get_tensor_model_parallel_world_size()
self.vocab_start_index, self.vocab_end_index ... | def __init__(self, num_embeddings: int, embedding_dim: int, params_dtype:
Optional[torch.dtype]=None):
super().__init__()
self.num_embeddings = num_embeddings
self.num_embeddings_padded = pad_vocab_size(num_embeddings)
self.embedding_dim = embedding_dim
if params_dtype is None:
params_dt... | null |
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 |
remove | if seq_id not in self.seqs_dict:
raise ValueError(f'Sequence {seq_id} not found.')
del self.seqs_dict[seq_id] | def remove(self, seq_id: int) ->None:
if seq_id not in self.seqs_dict:
raise ValueError(f'Sequence {seq_id} not found.')
del self.seqs_dict[seq_id] | null |
initialize_cluster | """Initialize the distributed cluster probably with Ray.
Args:
parallel_config: The configurations for parallel execution.
engine_use_ray: Whether to use Ray for async engine.
ray_address: The address of the Ray cluster. If None, uses
the default Ray cluster address.
Return... | def initialize_cluster(parallel_config: ParallelConfig, engine_use_ray:
bool=False, ray_address: Optional[str]=None) ->Optional['PlacementGroup']:
"""Initialize the distributed cluster probably with Ray.
Args:
parallel_config: The configurations for parallel execution.
engine_use_ray: Wheth... | Initialize the distributed cluster probably with Ray.
Args:
parallel_config: The configurations for parallel execution.
engine_use_ray: Whether to use Ray for async engine.
ray_address: The address of the Ray cluster. If None, uses
the default Ray cluster address.
Returns:
A tuple of (`distrib... |
get_quant_config | quant_cls = get_quantization_config(quantization)
hf_quant_config = getattr(hf_config, 'quantization_config', None)
if hf_quant_config is not None:
return quant_cls.from_config(hf_quant_config)
is_local = os.path.isdir(model_name_or_path)
if not is_local:
with get_lock(model_name_or_path, cache_dir):
hf... | def get_quant_config(quantization: str, model_name_or_path: str, hf_config:
PretrainedConfig, cache_dir: Optional[str]=None) ->QuantizationConfig:
quant_cls = get_quantization_config(quantization)
hf_quant_config = getattr(hf_config, 'quantization_config', None)
if hf_quant_config is not None:
r... | null |
from_config | weight_bits = cls.get_from_keys(config, ['w_bit', 'bits'])
group_size = cls.get_from_keys(config, ['q_group_size', 'group_size'])
zero_point = cls.get_from_keys(config, ['zero_point'])
return cls(weight_bits, group_size, zero_point) | @classmethod
def from_config(cls, config: Dict[str, Any]) ->'AWQConfig':
weight_bits = cls.get_from_keys(config, ['w_bit', 'bits'])
group_size = cls.get_from_keys(config, ['q_group_size', 'group_size'])
zero_point = cls.get_from_keys(config, ['zero_point'])
return cls(weight_bits, group_size, zero_point... | null |
set_weight_attrs | """Set attributes on a weight tensor.
This method is used to set attributes on a weight tensor. This method
will not overwrite existing attributes.
Args:
weight: The weight tensor.
weight_attrs: A dictionary of attributes to set on the weight tensor.
"""
if weight_attrs is None:
re... | def set_weight_attrs(weight: torch.Tensor, weight_attrs: Optional[Dict[str,
Any]]):
"""Set attributes on a weight tensor.
This method is used to set attributes on a weight tensor. This method
will not overwrite existing attributes.
Args:
weight: The weight tensor.
weight_attrs: A d... | Set attributes on a weight tensor.
This method is used to set attributes on a weight tensor. This method
will not overwrite existing attributes.
Args:
weight: The weight tensor.
weight_attrs: A dictionary of attributes to set on the weight tensor. |
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 |
_yarn_linear_ramp_mask | if low == high:
high += 0.001
linear_func = (torch.arange(dim, dtype=dtype, device=device) - low) / (high -
low)
ramp_func = torch.clamp(linear_func, 0, 1)
return ramp_func | def _yarn_linear_ramp_mask(low: float, high: float, dim: int, dtype: torch.
dtype, device: torch.device) ->torch.Tensor:
if low == high:
high += 0.001
linear_func = (torch.arange(dim, dtype=dtype, device=device) - low) / (high
- low)
ramp_func = torch.clamp(linear_func, 0, 1)
return... | null |
create_stream_response_json | choice_data = CompletionResponseStreamChoice(index=index, text=text,
logprobs=logprobs, finish_reason=finish_reason)
response = CompletionStreamResponse(id=request_id, created=created_time,
model=model_name, choices=[choice_data])
if usage is not None:
response.usage = usage
response_json = response.json(ex... | def create_stream_response_json(index: int, text: str, logprobs: Optional[
LogProbs]=None, finish_reason: Optional[str]=None, usage: Optional[
UsageInfo]=None) ->str:
choice_data = CompletionResponseStreamChoice(index=index, text=text,
logprobs=logprobs, finish_reason=finish_reason)
response = C... | null |
finished | return self._finished | @property
def finished(self) ->bool:
return self._finished | null |
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 |
abort_request | del request_id
self.abort_request_calls += 1 | def abort_request(self, request_id):
del request_id
self.abort_request_calls += 1 | null |
__init__ | if 'disable_log_stats' not in kwargs:
kwargs['disable_log_stats'] = True
engine_args = EngineArgs(model=model, tokenizer=tokenizer, tokenizer_mode=
tokenizer_mode, trust_remote_code=trust_remote_code,
tensor_parallel_size=tensor_parallel_size, dtype=dtype, quantization=
quantization, revision=revision, ... | def __init__(self, model: str, tokenizer: Optional[str]=None,
tokenizer_mode: str='auto', trust_remote_code: bool=False,
tensor_parallel_size: int=1, dtype: str='auto', quantization: Optional[
str]=None, revision: Optional[str]=None, tokenizer_revision: Optional[
str]=None, seed: int=0, gpu_memory_utili... | null |
from_config | """Create a config class from the model's quantization config."""
raise NotImplementedError | @classmethod
@abstractmethod
def from_config(cls, config: Dict[str, Any]) ->'QuantizationConfig':
"""Create a config class from the model's quantization config."""
raise NotImplementedError | Create a config class from the model's quantization config. |
_swap_out | if not self.block_manager.can_swap_out(seq_group):
raise RuntimeError(
'Aborted due to the lack of CPU swap space. Please increase the swap space to avoid this error.'
)
mapping = self.block_manager.swap_out(seq_group)
blocks_to_swap_out.update(mapping)
for seq in seq_group.get_seqs(status=SequenceS... | def _swap_out(self, seq_group: SequenceGroup, blocks_to_swap_out: Dict[int,
int]) ->None:
if not self.block_manager.can_swap_out(seq_group):
raise RuntimeError(
'Aborted due to the lack of CPU swap space. Please increase the swap space to avoid this error.'
)
mapping = self.b... | 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 'rotary_pos_emb.inv_freq' in name:
continue
if 'word_embeddings' in name:
name = name.replace('.word_embeddings', '... | 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 |
forward | w1_out, _ = self.w1(hidden_states)
w1_out = self.act_fn(w1_out)
w3_out, _ = self.w3(hidden_states)
current_hidden_states = w1_out * w3_out
current_hidden_states, _ = self.w2(current_hidden_states)
return current_hidden_states | def forward(self, hidden_states: torch.Tensor) ->torch.Tensor:
w1_out, _ = self.w1(hidden_states)
w1_out = self.act_fn(w1_out)
w3_out, _ = self.w3(hidden_states)
current_hidden_states = w1_out * w3_out
current_hidden_states, _ = self.w2(current_hidden_states)
return current_hidden_states | null |
execute_model | if self.is_driver_worker:
assert seq_group_metadata_list is not None
num_seq_groups = len(seq_group_metadata_list)
assert blocks_to_swap_in is not None
assert blocks_to_swap_out is not None
assert blocks_to_copy is not None
block_swapping_info = [blocks_to_swap_in, blocks_to_swap_out,
bl... | @torch.inference_mode()
def execute_model(self, seq_group_metadata_list: Optional[List[
SequenceGroupMetadata]]=None, blocks_to_swap_in: Optional[Dict[int, int
]]=None, blocks_to_swap_out: Optional[Dict[int, int]]=None,
blocks_to_copy: Optional[Dict[int, List[int]]]=None) ->Optional[
SamplerOutput]:
... | null |
_set_default_torch_dtype | """Sets the default torch dtype to the given dtype."""
old_dtype = torch.get_default_dtype()
torch.set_default_dtype(dtype)
yield
torch.set_default_dtype(old_dtype) | @contextlib.contextmanager
def _set_default_torch_dtype(dtype: torch.dtype):
"""Sets the default torch dtype to the given dtype."""
old_dtype = torch.get_default_dtype()
torch.set_default_dtype(dtype)
yield
torch.set_default_dtype(old_dtype) | Sets the default torch dtype to the given dtype. |
example_long_prompts | prompts = []
for filename in _LONG_PROMPTS:
prompts += _read_prompts(filename)
return prompts | @pytest.fixture
def example_long_prompts() ->List[str]:
prompts = []
for filename in _LONG_PROMPTS:
prompts += _read_prompts(filename)
return prompts | null |
__init__ | super().__init__()
self.config = config
self.linear_method = linear_method
self.model = MistralModel(config, linear_method)
self.lm_head = ParallelLMHead(config.vocab_size, config.hidden_size)
self.sampler = Sampler(config.vocab_size) | def __init__(self, config: MistralConfig, linear_method: Optional[
LinearMethodBase]=None) ->None:
super().__init__()
self.config = config
self.linear_method = linear_method
self.model = MistralModel(config, linear_method)
self.lm_head = ParallelLMHead(config.vocab_size, config.hidden_size)
... | null |
_append_tokens_to_blocks | cursor = 0
while cursor < len(token_ids):
if not self.logical_token_blocks:
self._append_logical_block()
last_block = self.logical_token_blocks[-1]
if last_block.is_full():
self._append_logical_block()
last_block = self.logical_token_blocks[-1]
num_empty_slots = last_block.get_nu... | def _append_tokens_to_blocks(self, token_ids: List[int]) ->None:
cursor = 0
while cursor < len(token_ids):
if not self.logical_token_blocks:
self._append_logical_block()
last_block = self.logical_token_blocks[-1]
if last_block.is_full():
self._append_logical_block... | null |
__init__ | self.weight_bits = weight_bits
self.group_size = group_size
self.desc_act = desc_act
self.pack_factor = 32 // self.weight_bits
if self.weight_bits != 4:
raise ValueError(
f'Currently, only 4-bit weight quantization is supported for GPTQ, but got {self.weight_bits} bits.'
) | def __init__(self, weight_bits: int, group_size: int, desc_act: bool) ->None:
self.weight_bits = weight_bits
self.group_size = group_size
self.desc_act = desc_act
self.pack_factor = 32 // self.weight_bits
if self.weight_bits != 4:
raise ValueError(
f'Currently, only 4-bit weight ... | null |
allocate | if not self.free_blocks:
raise ValueError('Out of memory! No free blocks are available.')
block = self.free_blocks.pop()
block.ref_count = 1
return block | def allocate(self) ->PhysicalTokenBlock:
if not self.free_blocks:
raise ValueError('Out of memory! No free blocks are available.')
block = self.free_blocks.pop()
block.ref_count = 1
return block | null |
free_finished_seq_groups | self.running = [seq_group for seq_group in self.running if not seq_group.
is_finished()] | def free_finished_seq_groups(self) ->None:
self.running = [seq_group for seq_group in self.running if not
seq_group.is_finished()] | null |
__init__ | self.block_number = block_number
self.block_size = block_size
self.token_ids = [_BLANK_TOKEN_ID] * block_size
self.num_tokens = 0 | def __init__(self, block_number: int, block_size: int) ->None:
self.block_number = block_number
self.block_size = block_size
self.token_ids = [_BLANK_TOKEN_ID] * block_size
self.num_tokens = 0 | 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 |
generate_greedy | outputs = self.generate(prompts, do_sample=False, max_new_tokens=max_tokens)
for i in range(len(outputs)):
output_ids, output_str = outputs[i]
outputs[i] = output_ids[0], output_str[0]
return outputs | def generate_greedy(self, prompts: List[str], max_tokens: int) ->List[Tuple
[List[int], str]]:
outputs = self.generate(prompts, do_sample=False, max_new_tokens=max_tokens
)
for i in range(len(outputs)):
output_ids, output_str = outputs[i]
outputs[i] = output_ids[0], output_str[0]
... | null |
forward | gate_up, _ = self.gate_up_proj(x)
x = self.act_fn(gate_up)
x, _ = self.down_proj(x)
return x | def forward(self, x):
gate_up, _ = self.gate_up_proj(x)
x = self.act_fn(gate_up)
x, _ = self.down_proj(x)
return x | null |
get_last_token_id | if not self.output_token_ids:
return self.prompt_token_ids[-1]
return self.output_token_ids[-1] | def get_last_token_id(self) ->int:
if not self.output_token_ids:
return self.prompt_token_ids[-1]
return self.output_token_ids[-1] | null |
fork_seq | self.block_manager.fork(parent_seq, child_seq) | def fork_seq(self, parent_seq: Sequence, child_seq: Sequence) ->None:
self.block_manager.fork(parent_seq, child_seq) | null |
__init__ | super().__init__()
self.weight = nn.Parameter(torch.ones(hidden_size))
self.variance_epsilon = eps | def __init__(self, hidden_size: int, eps: float=1e-06) ->None:
super().__init__()
self.weight = nn.Parameter(torch.ones(hidden_size))
self.variance_epsilon = eps | null |
forward | gate_up, _ = self.gate_up_proj(x)
x = self.act_fn(gate_up)
x, _ = self.down_proj(x)
return x | def forward(self, x):
gate_up, _ = self.gate_up_proj(x)
x = self.act_fn(gate_up)
x, _ = self.down_proj(x)
return x | null |
append_slot | """Allocate a physical slot for a new token."""
logical_blocks = seq.logical_token_blocks
block_table = self.block_tables[seq.seq_id]
if len(block_table) < len(logical_blocks):
if self.block_sliding_window and len(block_table
) >= self.block_sliding_window:
block_table.append(block_table[len(block_t... | def append_slot(self, seq: Sequence) ->Optional[Tuple[int, int]]:
"""Allocate a physical slot for a new token."""
logical_blocks = seq.logical_token_blocks
block_table = self.block_tables[seq.seq_id]
if len(block_table) < len(logical_blocks):
if self.block_sliding_window and len(block_table
... | Allocate a physical slot for a new token. |
get_node_and_gpu_ids | node_id = ray.get_runtime_context().get_node_id()
gpu_ids = ray.get_gpu_ids()
return node_id, gpu_ids | def get_node_and_gpu_ids(self) ->Tuple[str, List[int]]:
node_id = ray.get_runtime_context().get_node_id()
gpu_ids = ray.get_gpu_ids()
return node_id, gpu_ids | null |
forward | x, _ = self.dense_h_to_4h(x)
x = self.gelu_impl(x)
x, _ = self.dense_4h_to_h(x)
return x | def forward(self, x: torch.Tensor) ->torch.Tensor:
x, _ = self.dense_h_to_4h(x)
x = self.gelu_impl(x)
x, _ = self.dense_4h_to_h(x)
return x | 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 |
_apply_min_p | """
Adapted from
https://github.com/oobabooga/text-generation-webui/blob/3146124ec01f02c8fb1650a6517cf1b60b537aaf/modules/sampler_hijack.py#L16C17-L16C17
"""
probs = torch.softmax(logits, dim=-1)
top_probs, _ = probs.max(dim=-1, keepdim=True)
scaled_min_p = min_p.unsqueeze_(dim=1) * top_probs
tokens_to_remo... | def _apply_min_p(logits: torch.Tensor, min_p: torch.Tensor) ->torch.Tensor:
"""
Adapted from
https://github.com/oobabooga/text-generation-webui/blob/3146124ec01f02c8fb1650a6517cf1b60b537aaf/modules/sampler_hijack.py#L16C17-L16C17
"""
probs = torch.softmax(logits, dim=-1)
top_probs, _ = probs.max... | Adapted from
https://github.com/oobabooga/text-generation-webui/blob/3146124ec01f02c8fb1650a6517cf1b60b537aaf/modules/sampler_hijack.py#L16C17-L16C17 |
_init_engine | if not self.engine_use_ray:
engine_class = self._engine_class
elif self.worker_use_ray:
engine_class = ray.remote(num_cpus=0)(self._engine_class).remote
else:
cache_config = args[1]
parallel_config = args[2]
if parallel_config.tensor_parallel_size == 1:
num_gpus = cache_config.gpu_memory_uti... | def _init_engine(self, *args, **kwargs) ->Union[_AsyncLLMEngine,
'ray.ObjectRef']:
if not self.engine_use_ray:
engine_class = self._engine_class
elif self.worker_use_ray:
engine_class = ray.remote(num_cpus=0)(self._engine_class).remote
else:
cache_config = args[1]
paralle... | null |
forward | qkv, bias = self.query_key_value(hidden_states)
if bias is not None:
qkv += bias
q, k, v = qkv.split([self.q_size, self.kv_size, self.kv_size], dim=-1)
if self.use_rotary:
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)
attn_... | def forward(self, positions: torch.Tensor, hidden_states: torch.Tensor,
kv_cache: KVCache, input_metadata: InputMetadata) ->torch.Tensor:
qkv, bias = self.query_key_value(hidden_states)
if bias is not None:
qkv += bias
q, k, v = qkv.split([self.q_size, self.kv_size, self.kv_size], dim=-1)
if... | 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_name | return 'awq' | def get_name(self) ->str:
return 'awq' | null |
load_weights | stacked_params_mapping = [('gate_up_proj', 'w2', 0), ('gate_up_proj', 'w1', 1)]
params_dict = dict(self.named_parameters())
for name, loaded_weight in hf_model_weights_iterator(model_name_or_path,
cache_dir, load_format, revision):
if 'rotary_emb.inv_freq' in name:
continue
for param_name, weight_na... | 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 = [('gate_up_proj', 'w2', 0), ('gate_up_proj',
'w1', 1)]
params_dict = dict(self.named_parameters())
for name, loaded_weight in hf_model_... | null |
get_nvcc_cuda_version | """Get the CUDA version from nvcc.
Adapted from https://github.com/NVIDIA/apex/blob/8b7a1ff183741dd8f9b87e7bafd04cfde99cea28/setup.py
"""
nvcc_output = subprocess.check_output([cuda_dir + '/bin/nvcc', '-V'],
universal_newlines=True)
output = nvcc_output.split()
release_idx = output.index('release') + 1
nvc... | def get_nvcc_cuda_version(cuda_dir: str) ->Version:
"""Get the CUDA version from nvcc.
Adapted from https://github.com/NVIDIA/apex/blob/8b7a1ff183741dd8f9b87e7bafd04cfde99cea28/setup.py
"""
nvcc_output = subprocess.check_output([cuda_dir + '/bin/nvcc', '-V'],
universal_newlines=True)
output... | Get the CUDA version from nvcc.
Adapted from https://github.com/NVIDIA/apex/blob/8b7a1ff183741dd8f9b87e7bafd04cfde99cea28/setup.py |
_verify_greedy_sampling | if self.best_of > 1:
raise ValueError(
f'best_of must be 1 when using greedy sampling.Got {self.best_of}.') | def _verify_greedy_sampling(self) ->None:
if self.best_of > 1:
raise ValueError(
f'best_of must be 1 when using greedy sampling.Got {self.best_of}.'
) | null |
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 | hidden_states = self.transformer(input_ids, positions, kv_caches,
input_metadata)
hidden_states = self.lm_head.ln(hidden_states)
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)
hidden_states = self.lm_head.ln(hidden_states)
return hidden_states | 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 |
forward | ops.rotary_embedding(positions, query, key, self.head_size, self.
cos_sin_cache, self.is_neox_style)
return query, key | def forward(self, positions: torch.Tensor, query: torch.Tensor, key: torch.
Tensor) ->Tuple[torch.Tensor, torch.Tensor]:
ops.rotary_embedding(positions, query, key, self.head_size, self.
cos_sin_cache, self.is_neox_style)
return query, key | null |
_verify_non_beam_search | if self.early_stopping is not False:
raise ValueError(
'early_stopping is not effective and must be False when not using beam search.'
)
if self.length_penalty < 1.0 - _SAMPLING_EPS or self.length_penalty > 1.0 + _SAMPLING_EPS:
raise ValueError(
'length_penalty is not effective and must ... | def _verify_non_beam_search(self) ->None:
if self.early_stopping is not False:
raise ValueError(
'early_stopping is not effective and must be False when not using beam search.'
)
if (self.length_penalty < 1.0 - _SAMPLING_EPS or self.length_penalty >
1.0 + _SAMPLING_EPS):... | null |
__init__ | self.vocab_size = vocab_size
self.max_position_embeddings = max_position_embeddings
self.hidden_size = hidden_size
self.intermediate_size = intermediate_size
self.num_hidden_layers = num_hidden_layers
if num_key_value_heads is None:
num_key_value_heads = num_attention_heads
self.num_key_value_heads = num_key_value_... | def __init__(self, vocab_size=100008, hidden_size=4096, intermediate_size=
11008, num_hidden_layers=32, num_attention_heads=32,
num_key_value_heads=None, hidden_act='silu', max_position_embeddings=
2048, initializer_range=0.006, rms_norm_eps=1e-05, use_cache=True,
pad_token_id=0, bos_token_id=1, eos_tok... | null |
_set_config_defaults | for k, v in config_defaults.items():
if k not in config:
config[k] = v
return config | def _set_config_defaults(self, config: Dict[str, Any], config_defaults:
Dict[str, Any]) ->Dict[str, Any]:
for k, v in config_defaults.items():
if k not in config:
config[k] = v
return config | null |
__init__ | self.quant_config = quant_config | def __init__(self, quant_config: SqueezeLLMConfig):
self.quant_config = quant_config | null |
get_config_filenames | return ['quantize_config.json'] | @classmethod
def get_config_filenames(cls) ->List[str]:
return ['quantize_config.json'] | null |
__init__ | super().__init__()
hidden_size = config.n_embd
self.fc_in = ColumnParallelLinear(hidden_size, intermediate_size,
linear_method=linear_method)
self.fc_out = RowParallelLinear(intermediate_size, hidden_size,
linear_method=linear_method)
quant_config = getattr(linear_method, 'quant_config', None)
self.act = get_ac... | def __init__(self, intermediate_size: int, config: GPTJConfig,
linear_method: Optional[LinearMethodBase]=None):
super().__init__()
hidden_size = config.n_embd
self.fc_in = ColumnParallelLinear(hidden_size, intermediate_size,
linear_method=linear_method)
self.fc_out = RowParallelLinear(interm... | null |
test_get_prompt_logprobs | max_tokens = 5
hf_model = hf_runner(model, dtype=dtype)
hf_logprobs = hf_model.generate_greedy_logprobs(example_prompts, max_tokens
=max_tokens)
del hf_model
vllm_model = vllm_runner(model, dtype=dtype)
vllm_sampling_params = SamplingParams(max_tokens=max_tokens, logprobs=5,
prompt_logprobs=5, temperature=0.0)
... | @pytest.mark.parametrize('model', MODELS)
@pytest.mark.parametrize('dtype', ['half'])
def test_get_prompt_logprobs(hf_runner, vllm_runner, model, dtype,
example_prompts):
max_tokens = 5
hf_model = hf_runner(model, dtype=dtype)
hf_logprobs = hf_model.generate_greedy_logprobs(example_prompts,
max_... | null |
from_config | weight_bits = cls.get_from_keys(config, ['wbits'])
return cls(weight_bits) | @classmethod
def from_config(cls, config: Dict[str, Any]) ->'SqueezeLLMConfig':
weight_bits = cls.get_from_keys(config, ['wbits'])
return cls(weight_bits) | null |
_random_sample | random_samples = random_samples.cpu()
sample_idx = 0
results = []
for seq_group, is_prompt in zip(selected_seq_groups, is_prompts):
seq_ids, sampling_params = seq_group
num_parent_seqs = len(seq_ids)
if is_prompt:
parent_ids = [0] * sampling_params.best_of
next_token_ids = random_samples[sam... | def _random_sample(selected_seq_groups: List[Tuple[List[int],
SamplingParams]], is_prompts: List[bool], random_samples: torch.Tensor
) ->List[Tuple[List[int], List[int]]]:
random_samples = random_samples.cpu()
sample_idx = 0
results = []
for seq_group, is_prompt in zip(selected_seq_groups, is_pr... | null |
__init__ | super().__init__()
self.config = config
self.linear_method = linear_method
self.model = YiModel(config, linear_method)
self.lm_head = ParallelLMHead(config.vocab_size, config.hidden_size)
self.sampler = Sampler(config.vocab_size) | def __init__(self, config: YiConfig, linear_method: Optional[
LinearMethodBase]=None) ->None:
super().__init__()
self.config = config
self.linear_method = linear_method
self.model = YiModel(config, linear_method)
self.lm_head = ParallelLMHead(config.vocab_size, config.hidden_size)
self.sampl... | null |
forward | hidden_states = self.embed_tokens(input_ids)
for i in range(len(self.layers)):
layer = self.layers[i]
hidden_states = layer(positions, hidden_states, kv_caches[i],
input_metadata)
hidden_states = self.norm(hidden_states)
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.embed_tokens(input_ids)
for i in range(len(self.layers)):
layer = self.layers[i]
hidden_states = layer(positions, hidden_states, k... | null |
__init__ | super().__init__()
self.ln_1 = RMSNorm(config.hidden_size, eps=config.layer_norm_epsilon)
rope_theta = getattr(config, 'rope_theta', 10000)
rope_scaling = getattr(config, 'rope_scaling', None)
self.attn = QWenAttention(config.hidden_size, config.num_attention_heads,
config.max_position_embeddings, rope_theta=rope_t... | def __init__(self, config: QWenConfig, linear_method: Optional[
LinearMethodBase]=None):
super().__init__()
self.ln_1 = RMSNorm(config.hidden_size, eps=config.layer_norm_epsilon)
rope_theta = getattr(config, 'rope_theta', 10000)
rope_scaling = getattr(config, 'rope_scaling', None)
self.attn = QW... | null |
swap_in | mapping: Dict[PhysicalTokenBlock, PhysicalTokenBlock] = {}
for seq in seq_group.get_seqs(status=SequenceStatus.SWAPPED):
new_block_table: BlockTable = []
block_table = self.block_tables[seq.seq_id]
for cpu_block in block_table:
if cpu_block in mapping:
gpu_block = mapping[cpu_block]
... | def swap_in(self, seq_group: SequenceGroup) ->Dict[int, int]:
mapping: Dict[PhysicalTokenBlock, PhysicalTokenBlock] = {}
for seq in seq_group.get_seqs(status=SequenceStatus.SWAPPED):
new_block_table: BlockTable = []
block_table = self.block_tables[seq.seq_id]
for cpu_block in block_table... | null |
_build_sampler_output | sampler_output = []
for seq_group, sample_result, group_prompt_logprobs, group_sample_logprobs in zip(
sampling_metadata.seq_groups, sample_results, prompt_logprobs,
sample_logprobs):
seq_ids, _ = seq_group
next_token_ids, parent_ids = sample_result
seq_outputs = []
for parent_id, next_token_id,... | def _build_sampler_output(sample_results: List[Tuple[List[int], List[int]]],
sampling_metadata: SamplingMetadata, prompt_logprobs: List[Optional[
PromptLogprobs]], sample_logprobs: List[SampleLogprobs]) ->SamplerOutput:
sampler_output = []
for seq_group, sample_result, group_prompt_logprobs, group_sampl... | null |
apply_weights | qweight = weights['qweight']
qzeros = weights['qzeros']
scales = weights['scales']
pack_factor = self.quant_config.pack_factor
out_shape = x.shape[:-1] + (qweight.shape[-1] * pack_factor,)
reshaped_x = x.reshape(-1, x.shape[-1])
out = ops.awq_gemm(reshaped_x, qweight, scales, qzeros, pack_factor)
if bias is not None:
... | def apply_weights(self, weights: Dict[str, Any], x: torch.Tensor, bias:
Optional[torch.Tensor]=None) ->torch.Tensor:
qweight = weights['qweight']
qzeros = weights['qzeros']
scales = weights['scales']
pack_factor = self.quant_config.pack_factor
out_shape = x.shape[:-1] + (qweight.shape[-1] * pack... | null |
forward | hidden_states = self.embed_tokens(input_ids)
residual = None
for i in range(len(self.layers)):
layer = self.layers[i]
hidden_states, residual = layer(positions, hidden_states, kv_caches[i],
input_metadata, residual)
hidden_states, _ = self.norm(hidden_states, residual)
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.embed_tokens(input_ids)
residual = None
for i in range(len(self.layers)):
layer = self.layers[i]
hidden_states, residual = lay... | null |
build_demo | with gr.Blocks() as demo:
gr.Markdown('# vLLM text completion demo\n')
inputbox = gr.Textbox(label='Input', placeholder=
'Enter text and press ENTER')
outputbox = gr.Textbox(label='Output', placeholder=
'Generated result from the model')
inputbox.submit(http_bot, [inputbox], [outputbox])... | def build_demo():
with gr.Blocks() as demo:
gr.Markdown('# vLLM text completion demo\n')
inputbox = gr.Textbox(label='Input', placeholder=
'Enter text and press ENTER')
outputbox = gr.Textbox(label='Output', placeholder=
'Generated result from the model')
inpu... | null |
__init__ | super().__init__()
self.dense_h_to_4h = ColumnParallelLinear(config.hidden_size, config.
intermediate_size, linear_method=linear_method)
self.dense_4h_to_h = RowParallelLinear(config.intermediate_size, config.
hidden_size, linear_method=linear_method)
quant_config = getattr(linear_method, 'quant_config', None)
... | def __init__(self, config: GPTNeoXConfig, linear_method: Optional[
LinearMethodBase]=None):
super().__init__()
self.dense_h_to_4h = ColumnParallelLinear(config.hidden_size, config.
intermediate_size, linear_method=linear_method)
self.dense_4h_to_h = RowParallelLinear(config.intermediate_size, co... | null |
_convert_token_to_id | """Converts a token (str) in an id using the vocab."""
return self.sp_model.piece_to_id(token) | def _convert_token_to_id(self, token):
"""Converts a token (str) in an id using the vocab."""
return self.sp_model.piece_to_id(token) | Converts a token (str) in an id using the vocab. |
__init__ | super().__init__()
self.vocab_size = vocab_size | def __init__(self, vocab_size: int) ->None:
super().__init__()
self.vocab_size = vocab_size | null |
forward | if self.input_is_parallel:
input_parallel = input_
else:
tp_rank = get_tensor_model_parallel_rank()
splitted_input = split_tensor_along_last_dim(input_, num_partitions=
self.tp_size)
input_parallel = splitted_input[tp_rank].contiguous()
output_parallel = self.linear_method.apply_weights(self.lin... | def forward(self, input_):
if self.input_is_parallel:
input_parallel = input_
else:
tp_rank = get_tensor_model_parallel_rank()
splitted_input = split_tensor_along_last_dim(input_, num_partitions
=self.tp_size)
input_parallel = splitted_input[tp_rank].contiguous()
... | null |
forward | if residual is None:
residual = hidden_states
hidden_states = self.ln1(hidden_states)
else:
hidden_states, residual = self.ln1(hidden_states, residual)
hidden_states = self.self_attn(positions=positions, hidden_states=
hidden_states, kv_cache=kv_cache, input_metadata=input_metadata)
hidden_states, resid... | 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.ln1(hidden_states)
else:
... | null |
test_multi_query_kv_attention | random.seed(seed)
torch.random.manual_seed(seed)
torch.cuda.manual_seed(seed)
gpu_id = f'cuda:{device}'
max_len = min(MAX_SEQ_LEN, 4096)
seq_lens = random.sample(range(1, max_len), num_seqs)
num_tokens = sum(seq_lens)
scale = float(1.0 / head_size ** 0.5)
num_query_heads, num_kv_heads = num_heads
qkv = torch.empty(num_... | @pytest.mark.parametrize('num_seqs', NUM_PREFILL_SEQS)
@pytest.mark.parametrize('num_heads', NUM_HEADS)
@pytest.mark.parametrize('head_size', HEAD_SIZES)
@pytest.mark.parametrize('dtype', DTYPES)
@pytest.mark.parametrize('seed', SEEDS)
@pytest.mark.parametrize('device', DEVICES)
@torch.inference_mode()
def test_multi_q... | null |
allocate_cpu_cache | cpu_cache: List[KVCache] = []
key_block_shape = self.get_key_block_shape()
value_block_shape = self.get_value_block_shape()
pin_memory = not in_wsl()
if not pin_memory:
logger.warning(
"Using 'pin_memory=False' as WSL is detected. This may slow down the performance."
)
for _ in range(self.num_layers... | def allocate_cpu_cache(self) ->List[KVCache]:
cpu_cache: List[KVCache] = []
key_block_shape = self.get_key_block_shape()
value_block_shape = self.get_value_block_shape()
pin_memory = not in_wsl()
if not pin_memory:
logger.warning(
"Using 'pin_memory=False' as WSL is detected. Thi... | null |
weight_loader | parallel_dim = param.parallel_dim
assert loaded_weight.shape[parallel_dim] == self.num_embeddings
loaded_weight = loaded_weight[self.vocab_start_index:self.vocab_end_index]
param[:loaded_weight.shape[0]].data.copy_(loaded_weight) | def weight_loader(self, param: Parameter, loaded_weight: torch.Tensor):
parallel_dim = param.parallel_dim
assert loaded_weight.shape[parallel_dim] == self.num_embeddings
loaded_weight = loaded_weight[self.vocab_start_index:self.vocab_end_index]
param[:loaded_weight.shape[0]].data.copy_(loaded_weight) | null |
__init__ | super().__init__()
self.apply_residual_connection_post_layernorm = (config.
apply_residual_connection_post_layernorm)
self.fp32_residual_connection = config.fp32_residual_connection
layer_norm_func = RMSNorm if config.rmsnorm else LayerNorm
self.input_layernorm = layer_norm_func(config.hidden_size, eps=config.
... | def __init__(self, config, linear_method: Optional[LinearMethodBase]=None):
super().__init__()
self.apply_residual_connection_post_layernorm = (config.
apply_residual_connection_post_layernorm)
self.fp32_residual_connection = config.fp32_residual_connection
layer_norm_func = RMSNorm if config.rm... | null |
default_weight_loader | """Default weight loader."""
assert param.size() == loaded_weight.size()
param.data.copy_(loaded_weight) | def default_weight_loader(param: torch.Tensor, loaded_weight: torch.Tensor
) ->None:
"""Default weight loader."""
assert param.size() == loaded_weight.size()
param.data.copy_(loaded_weight) | Default weight loader. |
get_ip | return socket.gethostbyname(socket.gethostname()) | def get_ip() ->str:
return socket.gethostbyname(socket.gethostname()) | null |
_get_and_verify_max_len | """Get and verify the model's maximum length."""
derived_max_model_len = float('inf')
possible_keys = ['max_position_embeddings', 'n_positions', 'max_seq_len',
'seq_length', 'max_sequence_length', 'max_seq_length', 'seq_len']
for key in possible_keys:
max_len_key = getattr(hf_config, key, None)
if max_len_k... | def _get_and_verify_max_len(hf_config: PretrainedConfig, max_model_len:
Optional[int]) ->int:
"""Get and verify the model's maximum length."""
derived_max_model_len = float('inf')
possible_keys = ['max_position_embeddings', 'n_positions',
'max_seq_len', 'seq_length', 'max_sequence_length',
... | Get and verify the model's maximum length. |
get_min_capability | return 60 | @classmethod
def get_min_capability(cls) ->int:
return 60 | null |
sample_requests | with open(dataset_path) as f:
dataset = json.load(f)
dataset = [data for data in dataset if len(data['conversations']) >= 2]
dataset = [(data['conversations'][0]['value'], data['conversations'][1][
'value']) for data in dataset]
prompts = [prompt for prompt, _ in dataset]
prompt_token_ids = tokenizer(prompts).i... | def sample_requests(dataset_path: str, num_requests: int, tokenizer:
PreTrainedTokenizerBase) ->List[Tuple[str, int, int]]:
with open(dataset_path) as f:
dataset = json.load(f)
dataset = [data for data in dataset if len(data['conversations']) >= 2]
dataset = [(data['conversations'][0]['value'], ... | null |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.