Code
Hub
Workspaces
Following
Trending
Connect
MCP
copy
Create free account
hub
/
github.com/dhakalnirajan/LLaMA-BitNet
/ functions
Functions
24 in github.com/dhakalnirajan/LLaMA-BitNet
⨍
Functions
24
◇
Types & classes
2
↓ 2 callers
Function
_replace_linear_in_module
Recursively replaces every nn.Linear inside *module* with BitLinear, skipping the token embedding and lm_head (which stay full-precision).
utils.py:153
↓ 2 callers
Function
convert_to_bitnet
Convert a HuggingFace LlamaForCausalLM to a BitNet b1.58 model in-place. Steps (exactly as described in the training manuscript): 1. R
utils.py:181
↓ 2 callers
Function
generate
Generate text continuation for *prompt*. Args: model: The BitNet LlamaForCausalLM. tokenizer: Matching
inference.py:102
↓ 1 callers
Method
__init__
(self, dim: int, eps: float = 1e-6)
utils.py:73
↓ 1 callers
Function
_model_has_bitlinear
Return True if at least one module in the model is already a BitLinear.
inference.py:54
↓ 1 callers
Function
_quantize_activations_int8
Per-token absmax activation quantisation to int8 range [-127, 127]. scale = max(|x|, dim=-1) / 127 (per token, shape [batch, seq, 1]) x
utils.py:49
↓ 1 callers
Function
_quantize_weights_ternary
Absmean weight quantisation → {-1, 0, +1}. scale = mean(|W|) + ε (per weight-matrix, scalar) W_q = round_clamp(W / scale) vi
utils.py:32
↓ 1 callers
Function
_remove_decoder_prenorms
Remove the pre-attention and pre-FFN RMSNorms from every decoder layer. Per the paper: "Remove RMSNorm before attention and SwiGLU because
utils.py:165
↓ 1 callers
Function
build_dataloader
Load and tokenise the dataset. The dataset is expected to have a "text" column. Each example is tokenised and truncated / padded to `co
train.py:114
↓ 1 callers
Function
build_model
Build a small LLaMA 2 model from scratch, then convert to BitNet.
train.py:155
↓ 1 callers
Function
count_parameters
(model: nn.Module)
train.py:106
↓ 1 callers
Method
from_linear
Construct a BitLinear from an existing nn.Linear, copying its weight.
utils.py:134
↓ 1 callers
Function
get_autocast_ctx
Return a bf16 autocast context when supported, otherwise a no-op.
train.py:97
↓ 1 callers
Function
get_device
()
train.py:89
↓ 1 callers
Function
get_device
()
inference.py:46
↓ 1 callers
Function
load_model
Load model and tokenizer from *model_path*. If the saved model does not yet contain BitLinear layers (e.g. a plain LLaMA checkpoint), th
inference.py:59
↓ 1 callers
Function
main
()
inference.py:173
↓ 1 callers
Function
parse_args
()
train.py:294
↓ 1 callers
Function
parse_args
()
inference.py:159
↓ 1 callers
Function
train
(cfg: dict)
train.py:178
Method
__init__
( self, in_features: int, out_features: int, bias: bool = False, # pa
utils.py:103
Method
forward
(self, x: torch.Tensor)
utils.py:78
Method
forward
(self, x: torch.Tensor)
utils.py:114
Function
tokenise
(batch)
train.py:127