|
AQIT 0.1.0
|
Public Member Functions | |
| None | __init__ (self, Any hf_model, Any tokenizer, *, str hf_name, int n_layers, int d_model, int n_heads) |
| nn.Module | ln_final (self) |
| _UnembedShim | unembed (self) |
| HfLlmShim | from_pretrained (cls, str hf_name, dict[str, Any] cfg, *, torch.dtype dtype, str device, dict[str, Any]|None hf_kwargs=None) |
| torch.Tensor | W_E (self) |
| torch.Tensor | W_U (self) |
| list[Any] | blocks (self) |
| HfLlmShim | eval (self) |
| parameters (self, bool recurse=True) | |
| named_parameters (self, str prefix="", bool recurse=True) | |
| HfLlmShim | to (self, str|torch.device device) |
| torch.Tensor | to_tokens (self, str|torch.Tensor text, bool prepend_bos=False) |
| str | to_string (self, Any tokens) |
| torch.Tensor | __call__ (self, torch.Tensor tokens) |
| tuple[torch.Tensor, dict[str, torch.Tensor]] | run_with_cache (self, torch.Tensor tokens, Any names_filter=None, str|None return_type="logits") |
| torch.Tensor | run_with_hooks (self, torch.Tensor tokens, list[tuple[str, Callable[..., torch.Tensor]]]|None fwd_hooks=None, str|None return_type="logits") |
Public Attributes | |
| hf_model = hf_model | |
| tokenizer = tokenizer | |
| cfg | |
| device = next(hf_model.parameters()).device | |
Protected Member Functions | |
| torch.Tensor | _forward_logits (self, torch.Tensor tokens) |
| tuple[set[int], set[int], bool] | _hooks_from_filter (self, Any names_filter) |
Protected Attributes | |
| _backbone | |
| _layers | |
| _embed | |
| _lm_head = _resolve_modules(hf_model) | |
| tuple | _final_norm |
| _unembed = _UnembedShim(self.W_U, head_bias) | |
Enough of HookedTransformer for SAE capture, steering, and eval logits.
Definition at line 135 of file hf_llm_shim.py.
| None aquin.compute.hf_llm_shim.HfLlmShim.__init__ | ( | self, | |
| Any | hf_model, | ||
| Any | tokenizer, | ||
| * | , | ||
| str | hf_name, | ||
| int | n_layers, | ||
| int | d_model, | ||
| int | n_heads ) |
Definition at line 138 of file hf_llm_shim.py.
| torch.Tensor aquin.compute.hf_llm_shim.HfLlmShim.__call__ | ( | self, | |
| torch.Tensor | tokens ) |
Definition at line 262 of file hf_llm_shim.py.
References _forward_logits().
|
protected |
Definition at line 265 of file hf_llm_shim.py.
References hf_model.
Referenced by __call__(), run_with_cache(), and run_with_hooks().
|
protected |
Definition at line 270 of file hf_llm_shim.py.
References aquin.compute.hf_llm_shim._names_filter_match(), and cfg.
Referenced by run_with_cache().
| list[Any] aquin.compute.hf_llm_shim.HfLlmShim.blocks | ( | self | ) |
Definition at line 225 of file hf_llm_shim.py.
References _layers.
| HfLlmShim aquin.compute.hf_llm_shim.HfLlmShim.eval | ( | self | ) |
Definition at line 228 of file hf_llm_shim.py.
References eval(), and hf_model.
Referenced by eval().
| HfLlmShim aquin.compute.hf_llm_shim.HfLlmShim.from_pretrained | ( | cls, | |
| str | hf_name, | ||
| dict[str, Any] | cfg, | ||
| * | , | ||
| torch.dtype | dtype, | ||
| str | device, | ||
| dict[str, Any] | None | hf_kwargs = None ) |
Definition at line 175 of file hf_llm_shim.py.
References aquin.compute.hf_llm_shim._hf_load_device_map().
| nn.Module aquin.compute.hf_llm_shim.HfLlmShim.ln_final | ( | self | ) |
Definition at line 167 of file hf_llm_shim.py.
References _final_norm.
| aquin.compute.hf_llm_shim.HfLlmShim.named_parameters | ( | self, | |
| str | prefix = "", | ||
| bool | recurse = True ) |
Definition at line 235 of file hf_llm_shim.py.
References hf_model, and named_parameters().
Referenced by named_parameters().
| aquin.compute.hf_llm_shim.HfLlmShim.parameters | ( | self, | |
| bool | recurse = True ) |
Definition at line 232 of file hf_llm_shim.py.
References hf_model, and parameters().
Referenced by parameters(), and to().
| tuple[torch.Tensor, dict[str, torch.Tensor]] aquin.compute.hf_llm_shim.HfLlmShim.run_with_cache | ( | self, | |
| torch.Tensor | tokens, | ||
| Any | names_filter = None, | ||
| str | None | return_type = "logits" ) |
Definition at line 284 of file hf_llm_shim.py.
References _embed, _forward_logits(), _hooks_from_filter(), _layers, and hf_model.
| torch.Tensor aquin.compute.hf_llm_shim.HfLlmShim.run_with_hooks | ( | self, | |
| torch.Tensor | tokens, | ||
| list[tuple[str, Callable[..., torch.Tensor]]] | None | fwd_hooks = None, | ||
| str | None | return_type = "logits" ) |
Definition at line 336 of file hf_llm_shim.py.
References _embed, _forward_logits(), and _layers.
| HfLlmShim aquin.compute.hf_llm_shim.HfLlmShim.to | ( | self, | |
| str | torch.device | device ) |
Definition at line 238 of file hf_llm_shim.py.
References aquin.compute.hf_llm_shim._model_has_device_map(), device, hf_model, parameters(), and to().
Referenced by to().
| str aquin.compute.hf_llm_shim.HfLlmShim.to_string | ( | self, | |
| Any | tokens ) |
Definition at line 255 of file hf_llm_shim.py.
References tokenizer.
| torch.Tensor aquin.compute.hf_llm_shim.HfLlmShim.to_tokens | ( | self, | |
| str | torch.Tensor | text, | ||
| bool | prepend_bos = False ) |
Definition at line 245 of file hf_llm_shim.py.
| _UnembedShim aquin.compute.hf_llm_shim.HfLlmShim.unembed | ( | self | ) |
Definition at line 171 of file hf_llm_shim.py.
References _unembed.
| torch.Tensor aquin.compute.hf_llm_shim.HfLlmShim.W_E | ( | self | ) |
Definition at line 215 of file hf_llm_shim.py.
References _embed.
| torch.Tensor aquin.compute.hf_llm_shim.HfLlmShim.W_U | ( | self | ) |
Definition at line 219 of file hf_llm_shim.py.
References _lm_head.
|
protected |
Definition at line 156 of file hf_llm_shim.py.
|
protected |
Definition at line 156 of file hf_llm_shim.py.
Referenced by run_with_cache(), run_with_hooks(), and W_E().
|
protected |
Definition at line 158 of file hf_llm_shim.py.
Referenced by ln_final().
|
protected |
Definition at line 156 of file hf_llm_shim.py.
Referenced by blocks(), run_with_cache(), and run_with_hooks().
|
protected |
Definition at line 156 of file hf_llm_shim.py.
Referenced by W_U().
|
protected |
Definition at line 164 of file hf_llm_shim.py.
Referenced by unembed().
| aquin.compute.hf_llm_shim.HfLlmShim.cfg |
Definition at line 150 of file hf_llm_shim.py.
Referenced by _hooks_from_filter().
| aquin.compute.hf_llm_shim.HfLlmShim.device = next(hf_model.parameters()).device |
Definition at line 157 of file hf_llm_shim.py.
Referenced by to(), and to_tokens().
| aquin.compute.hf_llm_shim.HfLlmShim.hf_model = hf_model |
Definition at line 148 of file hf_llm_shim.py.
Referenced by _forward_logits(), eval(), named_parameters(), parameters(), run_with_cache(), and to().
| aquin.compute.hf_llm_shim.HfLlmShim.tokenizer = tokenizer |
Definition at line 149 of file hf_llm_shim.py.
Referenced by to_string(), and to_tokens().