MCPcopy Create free account
hub / github.com/NVIDIA/TensorRT-LLM / UnquantizedLinearMethod

Class UnquantizedLinearMethod

tensorrt_llm/_torch/modules/linear.py:377–447  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

375
376
377class UnquantizedLinearMethod(LinearMethodBase):
378
379 def create_weights(self, module: Linear, in_features: int,
380 out_features: int, bias: bool, dtype: torch.dtype):
381 weight_shape = (out_features, in_features)
382 module.weight = Parameter(torch.empty(weight_shape, dtype=dtype),
383 requires_grad=False)
384
385 if bias:
386 module.bias = Parameter(torch.empty((out_features), dtype=dtype),
387 requires_grad=False)
388 else:
389 module.register_parameter("bias", None)
390
391 def apply(self, module: Linear, input: torch.Tensor,
392 bias: Optional[torch.Tensor]):
393 if module.use_custom_cublas_mm:
394 output = torch.ops.trtllm.cublas_mm(input,
395 module.weight.t(),
396 bias,
397 out_dtype=None)
398 else:
399 output = F.linear(input, module.weight, bias)
400 return output
401
402 def load_weights_vanilla(self,
403 module: Linear,
404 weights: List[Dict],
405 allow_partial_loading: bool = False) -> None:
406 load_weights_vanilla_helper(module,
407 weights,
408 allow_partial_loading=allow_partial_loading)
409
410 def load_weights_fused_qkv_linear(
411 self,
412 module: Linear,
413 weights: List[Dict],
414 allow_partial_loading: bool = False) -> None:
415 q_weight, k_weight, v_weight = load_weights_fused_qkv_helper(
416 module, weights, allow_partial_loading=allow_partial_loading)
417 if not allow_partial_loading:
418 copy_weight(module.weight, torch.cat(
419 (q_weight, k_weight, v_weight)))
420 else:
421 for shard_key, weight in zip(('q', 'k', 'v'),
422 (q_weight, k_weight, v_weight)):
423 if weight is not None:
424 assert shard_key in module.fused_weight_shard_indices_mapping, f"Shard key {shard_key} not found in fused weight shard indices mapping"
425 shard_offset, shard_size = module.fused_weight_shard_indices_mapping[
426 shard_key]
427 copy_weight_shard(module.weight, weight, shard_offset,
428 shard_size)
429
430 def load_weights_fused_gate_up_linear(
431 self,
432 module: Linear,
433 weights: List[Dict],
434 allow_partial_loading: bool = False) -> None:

Callers 1

get_quant_methodFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected