Local language model for reflection-augmentation. The model is lazily loaded on first ``generate()`` call. If ``enabled`` is ``False``, ``generate()`` returns an empty :class:`RAMOutput` without ever allocating GPU memory. Parameters ---------- model_name_or_path : str
| 99 | |
| 100 | |
| 101 | class RAMModule: |
| 102 | """Local language model for reflection-augmentation. |
| 103 | |
| 104 | The model is lazily loaded on first ``generate()`` call. If ``enabled`` |
| 105 | is ``False``, ``generate()`` returns an empty :class:`RAMOutput` without |
| 106 | ever allocating GPU memory. |
| 107 | |
| 108 | Parameters |
| 109 | ---------- |
| 110 | model_name_or_path : str |
| 111 | HuggingFace model ID or local path. |
| 112 | backend : str |
| 113 | ``"hf"`` for HuggingFace Transformers, ``"vllm"`` for vLLM HTTP API. |
| 114 | vllm_url : str |
| 115 | Base URL for vLLM server (only used when ``backend="vllm"``). |
| 116 | max_new_tokens : int |
| 117 | Maximum tokens to generate. |
| 118 | temperature : float |
| 119 | Sampling temperature. |
| 120 | device : str |
| 121 | PyTorch device string. ``"auto"`` selects GPU if available. |
| 122 | enabled : bool |
| 123 | Master toggle. When ``False``, ``generate()`` is a no-op. |
| 124 | checkpoint_path : str |
| 125 | Path to a LoRA adapter checkpoint. Empty string means no adapter. |
| 126 | """ |
| 127 | |
| 128 | def __init__( |
| 129 | self, |
| 130 | model_name_or_path: str = "Qwen/Qwen2.5-7B-Instruct", |
| 131 | backend: str = "hf", |
| 132 | vllm_url: str = "", |
| 133 | max_new_tokens: int = 1024, |
| 134 | temperature: float = 0.3, |
| 135 | device: str = "auto", |
| 136 | enabled: bool = True, |
| 137 | checkpoint_path: str = "", |
| 138 | ) -> None: |
| 139 | self.model_name_or_path = model_name_or_path |
| 140 | self.backend = RAMBackend(backend) |
| 141 | self.vllm_url = vllm_url.rstrip("/") |
| 142 | self.max_new_tokens = max_new_tokens |
| 143 | self.temperature = temperature |
| 144 | self.device = device |
| 145 | self.enabled = enabled |
| 146 | self.checkpoint_path = checkpoint_path |
| 147 | |
| 148 | # Populated by _lazy_load() |
| 149 | self._model = None |
| 150 | self._tokenizer = None |
| 151 | self._loaded = False |
| 152 | |
| 153 | # ---- properties ------------------------------------------------------- |
| 154 | |
| 155 | @property |
| 156 | def is_loaded(self) -> bool: |
| 157 | return self._loaded |
| 158 |