socket-lm 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (78) hide show
  1. socket_lm-0.1.0/LICENSE +21 -0
  2. socket_lm-0.1.0/PKG-INFO +199 -0
  3. socket_lm-0.1.0/README.md +150 -0
  4. socket_lm-0.1.0/pyproject.toml +37 -0
  5. socket_lm-0.1.0/setup.cfg +4 -0
  6. socket_lm-0.1.0/socket_lm.egg-info/PKG-INFO +199 -0
  7. socket_lm-0.1.0/socket_lm.egg-info/SOURCES.txt +76 -0
  8. socket_lm-0.1.0/socket_lm.egg-info/dependency_links.txt +1 -0
  9. socket_lm-0.1.0/socket_lm.egg-info/requires.txt +8 -0
  10. socket_lm-0.1.0/socket_lm.egg-info/top_level.txt +1 -0
  11. socket_lm-0.1.0/socketimport/__init__.py +161 -0
  12. socket_lm-0.1.0/socketimport/config.py +103 -0
  13. socket_lm-0.1.0/socketimport/core/__init__.py +42 -0
  14. socket_lm-0.1.0/socketimport/core/accelerator.py +89 -0
  15. socket_lm-0.1.0/socketimport/core/attention.py +51 -0
  16. socket_lm-0.1.0/socketimport/core/base.py +87 -0
  17. socket_lm-0.1.0/socketimport/core/galore.py +308 -0
  18. socket_lm-0.1.0/socketimport/core/lite_ladder.py +330 -0
  19. socket_lm-0.1.0/socketimport/core/lora.py +394 -0
  20. socket_lm-0.1.0/socketimport/core/model_loader.py +86 -0
  21. socket_lm-0.1.0/socketimport/core/quantization.py +93 -0
  22. socket_lm-0.1.0/socketimport/core/reft.py +300 -0
  23. socket_lm-0.1.0/socketimport/data/__init__.py +3 -0
  24. socket_lm-0.1.0/socketimport/data/loader.py +65 -0
  25. socket_lm-0.1.0/socketimport/deps.py +67 -0
  26. socket_lm-0.1.0/socketimport/device.py +172 -0
  27. socket_lm-0.1.0/socketimport/distributed/__init__.py +131 -0
  28. socket_lm-0.1.0/socketimport/errors.py +247 -0
  29. socket_lm-0.1.0/socketimport/memory/__init__.py +17 -0
  30. socket_lm-0.1.0/socketimport/memory/batch_finder.py +109 -0
  31. socket_lm-0.1.0/socketimport/memory/checkpointing.py +78 -0
  32. socket_lm-0.1.0/socketimport/memory/tracker.py +85 -0
  33. socket_lm-0.1.0/socketimport/optim/__init__.py +19 -0
  34. socket_lm-0.1.0/socketimport/optim/ema.py +69 -0
  35. socket_lm-0.1.0/socketimport/optim/fused.py +56 -0
  36. socket_lm-0.1.0/socketimport/optim/lion.py +68 -0
  37. socket_lm-0.1.0/socketimport/optim/scheduler.py +83 -0
  38. socket_lm-0.1.0/socketimport/optim/swa.py +63 -0
  39. socket_lm-0.1.0/socketimport/profiler/__init__.py +4 -0
  40. socket_lm-0.1.0/socketimport/profiler/benchmark.py +87 -0
  41. socket_lm-0.1.0/socketimport/profiler/trace.py +43 -0
  42. socket_lm-0.1.0/socketimport/training/__init__.py +25 -0
  43. socket_lm-0.1.0/socketimport/training/callbacks.py +102 -0
  44. socket_lm-0.1.0/socketimport/training/framework_adapter.py +89 -0
  45. socket_lm-0.1.0/socketimport/training/oom_recovery.py +109 -0
  46. socket_lm-0.1.0/socketimport/training/trainer.py +194 -0
  47. socket_lm-0.1.0/socketimport/training/vram_guard.py +125 -0
  48. socket_lm-0.1.0/socketimport/utils.py +63 -0
  49. socket_lm-0.1.0/tests/test_accelerator.py +124 -0
  50. socket_lm-0.1.0/tests/test_attention.py +56 -0
  51. socket_lm-0.1.0/tests/test_batch_finder.py +148 -0
  52. socket_lm-0.1.0/tests/test_benchmark.py +78 -0
  53. socket_lm-0.1.0/tests/test_callbacks.py +94 -0
  54. socket_lm-0.1.0/tests/test_checkpointing.py +141 -0
  55. socket_lm-0.1.0/tests/test_config.py +98 -0
  56. socket_lm-0.1.0/tests/test_deps.py +73 -0
  57. socket_lm-0.1.0/tests/test_device.py +140 -0
  58. socket_lm-0.1.0/tests/test_distributed.py +136 -0
  59. socket_lm-0.1.0/tests/test_ema.py +115 -0
  60. socket_lm-0.1.0/tests/test_errors.py +214 -0
  61. socket_lm-0.1.0/tests/test_framework_adapter.py +72 -0
  62. socket_lm-0.1.0/tests/test_fused.py +107 -0
  63. socket_lm-0.1.0/tests/test_galore.py +349 -0
  64. socket_lm-0.1.0/tests/test_lion.py +96 -0
  65. socket_lm-0.1.0/tests/test_lite_ladder.py +375 -0
  66. socket_lm-0.1.0/tests/test_loader.py +106 -0
  67. socket_lm-0.1.0/tests/test_lora.py +558 -0
  68. socket_lm-0.1.0/tests/test_model_loader.py +111 -0
  69. socket_lm-0.1.0/tests/test_oom_recovery.py +107 -0
  70. socket_lm-0.1.0/tests/test_quantization.py +112 -0
  71. socket_lm-0.1.0/tests/test_reft.py +337 -0
  72. socket_lm-0.1.0/tests/test_scheduler.py +98 -0
  73. socket_lm-0.1.0/tests/test_swa.py +71 -0
  74. socket_lm-0.1.0/tests/test_trace.py +53 -0
  75. socket_lm-0.1.0/tests/test_tracker.py +86 -0
  76. socket_lm-0.1.0/tests/test_trainer.py +250 -0
  77. socket_lm-0.1.0/tests/test_utils.py +75 -0
  78. socket_lm-0.1.0/tests/test_vram_guard.py +123 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Ömür Bera Işık
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,199 @@
1
+ Metadata-Version: 2.4
2
+ Name: socket-lm
3
+ Version: 0.1.0
4
+ Summary: A training-speed-focused LoRA/PEFT library offering four parameter-efficient fine-tuning methods (LoRA, ReFT, LiteLadder, GaLore)
5
+ Author: Omur Bera Isik
6
+ License: MIT License
7
+
8
+ Copyright (c) 2026 Ömür Bera Işık
9
+
10
+ Permission is hereby granted, free of charge, to any person obtaining a copy
11
+ of this software and associated documentation files (the "Software"), to deal
12
+ in the Software without restriction, including without limitation the rights
13
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
+ copies of the Software, and to permit persons to whom the Software is
15
+ furnished to do so, subject to the following conditions:
16
+
17
+ The above copyright notice and this permission notice shall be included in all
18
+ copies or substantial portions of the Software.
19
+
20
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
+ SOFTWARE.
27
+
28
+ Keywords: lora,peft,fine-tuning,pytorch,llm,deep-learning
29
+ Classifier: Development Status :: 3 - Alpha
30
+ Classifier: Intended Audience :: Science/Research
31
+ Classifier: Intended Audience :: Developers
32
+ Classifier: License :: OSI Approved :: MIT License
33
+ Classifier: Programming Language :: Python :: 3
34
+ Classifier: Programming Language :: Python :: 3.9
35
+ Classifier: Programming Language :: Python :: 3.10
36
+ Classifier: Programming Language :: Python :: 3.11
37
+ Classifier: Programming Language :: Python :: 3.12
38
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
39
+ Requires-Python: >=3.9
40
+ Description-Content-Type: text/markdown
41
+ License-File: LICENSE
42
+ Requires-Dist: torch>=2.0
43
+ Provides-Extra: quantization
44
+ Requires-Dist: bitsandbytes>=0.41.0; extra == "quantization"
45
+ Provides-Extra: dev
46
+ Requires-Dist: pytest>=7.0; extra == "dev"
47
+ Requires-Dist: bitsandbytes>=0.41.0; extra == "dev"
48
+ Dynamic: license-file
49
+
50
+ # Socket
51
+
52
+ A LoRA/PEFT library focused on training speed. Offers four different parameter-efficient
53
+ fine-tuning methods — all written from scratch with no dependency on external PEFT libraries
54
+ (`peft` etc.).
55
+
56
+ ```bash
57
+ pip install socket
58
+ ```
59
+
60
+ > **Important:** PyPI package name is `socket`, but to avoid clashing with Python's built-in `socket`
61
+ > (networking) module, **the import name is `socketimport`**:
62
+ > ```python
63
+ > import socketimport as sk
64
+ > ```
65
+
66
+ ## Methods
67
+
68
+ | Method | What it does | Status |
69
+ |---|---|---|
70
+ | **LoRA** (+ rsLoRA, DoRA) | Low-rank addition to weights: `W + (α/r)·BA` | Mature, tested |
71
+ | **ReFT** (LoReFT) | Intervenes in hidden representations, not weights | Mature, tested |
72
+ | **LiteLadder** | Trains a separate "side network" with no backprop to backbone | **Experimental** — validated at small scale, not yet tested with real language data |
73
+ | **GaLore** | Full-parameter training with low-rank gradient projection to reduce optimizer memory | Mature, tested |
74
+
75
+ When to use each method differs: LoRA/ReFT/LiteLadder reduce parameter count (adapter-based),
76
+ while GaLore allows **full-parameter** training but only reduces optimizer memory — they are not
77
+ interchangeable, but complementary tools.
78
+
79
+ ## Quick Start
80
+
81
+ ### LoRA
82
+
83
+ ```python
84
+ import torch
85
+ from socketimport import LoRAAdapter, LoRAConfig
86
+
87
+ model = ... # any nn.Module (e.g., a Llama model)
88
+ config = LoRAConfig(r=16, alpha=32, use_rslora=True, dropout=0.05)
89
+ adapter = LoRAAdapter(model, config)
90
+
91
+ optimizer = torch.optim.AdamW(adapter.trainable_parameters(), lr=1e-4)
92
+ # ... normal training loop, forward with adapter(x) ...
93
+
94
+ adapter.merge() # zero-overhead embedding for inference
95
+ saved = adapter.adapter_state_dict() # only LoRA weights (KB not MB)
96
+ ```
97
+
98
+ Config parameters accept alternative names
99
+ (`rank`, `lora_r`, `lora_alpha`, `dora`, `rslora` etc.) — if conflicting values
100
+ are provided, an error is raised, not silently chosen.
101
+
102
+ ### ReFT
103
+
104
+ ```python
105
+ from socketimport import ReFTAdapter, ReFTConfig
106
+
107
+ # `layers` must be provided explicitly - Socket does not attempt to guess model architecture
108
+ adapter = ReFTAdapter(
109
+ model, layers=model.model.layers, embed_dim=4096,
110
+ config=ReFTConfig(r=4, layers=(8, 16, 24)),
111
+ )
112
+ optimizer = torch.optim.AdamW(adapter.trainable_parameters(), lr=1e-3)
113
+ ```
114
+
115
+ ### LiteLadder (experimental)
116
+
117
+ ```python
118
+ from socketimport import LiteLadderAdapter, LiteLadderConfig
119
+
120
+ adapter = LiteLadderAdapter(
121
+ model, layers=model.model.layers, embed_dim=4096, output_dim=32000,
122
+ config=LiteLadderConfig(side_width=256, rank=32, n_taps=4),
123
+ )
124
+ ```
125
+
126
+ Backward never enters the backbone (showed much lower overhead than LoRA as depth increased in
127
+ small-scale tests) — but this has only been validated on synthetic tasks with a single CPU core.
128
+ **Not recommended** as production default; should be considered an opt-in experimental option.
129
+
130
+ ### GaLore
131
+
132
+ ```python
133
+ from socketimport import GaLoreAdamW, GaLoreConfig, create_galore_param_groups
134
+
135
+ groups = create_galore_param_groups(model, GaLoreConfig(rank=128, update_proj_gap=200))
136
+ optimizer = GaLoreAdamW(groups, lr=1e-4)
137
+ # Model is trained FULL-PARAMETER - no adapter, no merge, GaLore
138
+ # only reduces optimizer memory usage
139
+ ```
140
+
141
+ `GaLoreAdamW` does **not** implement `SocketAdapterBase` — it is not an adapter,
142
+ but a standard `torch.optim.Optimizer` subclass.
143
+
144
+ ## Architecture
145
+
146
+ ```
147
+ socketimport/
148
+ ├── core/
149
+ │ ├── base.py # SocketAdapterBase - shared interface for LoRA/ReFT/LiteLadder
150
+ │ ├── lora.py
151
+ │ ├── reft.py
152
+ │ ├── lite_ladder.py
153
+ │ └── galore.py
154
+ ```
155
+
156
+ All adapter classes (`LoRAAdapter`, `ReFTAdapter`, `LiteLadderAdapter`)
157
+ share the same `SocketAdapterBase` interface: `trainable_parameters()`,
158
+ `merge()`/`unmerge()`, `adapter_state_dict()`/`load_adapter_state_dict()`.
159
+ This allows the training infrastructure (trainer, distributed, profiler) to be
160
+ written independently of which method is selected.
161
+
162
+ ## Development
163
+
164
+ ```bash
165
+ pip install -e ".[dev]"
166
+ pytest tests/ -v
167
+ ```
168
+
169
+ 444 tests covering all modules: mathematical correctness (e.g., zero-initialization as no-op,
170
+ merge/unmerge being inverses), model freezing behavior, end-to-end training actually reducing loss,
171
+ and save/load round-trips.
172
+
173
+ > **Note:** `quantize_linear`/`quantize_model` and their tests require `bitsandbytes`
174
+ > (see [Dependencies](#dependencies)). The `dev` extra installs this automatically; if not installed,
175
+ > quantization tests will fail with `DependencyError` (not a library error).
176
+
177
+ ## Dependencies
178
+
179
+ | Package | Required? | For |
180
+ |---|---|---|
181
+ | `torch>=2.0` | Yes | Entire library |
182
+ | `bitsandbytes>=0.41.0` | No (`pip install socket[quantization]`) | Only `quantize_linear`/`quantize_model` (4-bit/8-bit weight quantization) |
183
+
184
+ All other features (LoRA, ReFT, LiteLadder, GaLore, checkpointing, OOM recovery,
185
+ VRAM guard, distributed backend selection, etc.) work with `torch` alone.
186
+
187
+ ## Limitations (honestly)
188
+
189
+ - All tests run on 1 CPU core with small synthetic tasks — no scale testing on GPU
190
+ or with real language data yet.
191
+ - LiteLadder is not a published method; Socket-specific architecture tested at small scale
192
+ (combination of LST + ReFT-style lightweight interventions).
193
+ - No multi-seed statistical validation; results are single-seed.
194
+
195
+ -Note: PyPI does not normally allow this package name; please use -pip install socket-lm- to install it.
196
+
197
+ ## License
198
+
199
+ MIT — see [LICENSE](LICENSE).
@@ -0,0 +1,150 @@
1
+ # Socket
2
+
3
+ A LoRA/PEFT library focused on training speed. Offers four different parameter-efficient
4
+ fine-tuning methods — all written from scratch with no dependency on external PEFT libraries
5
+ (`peft` etc.).
6
+
7
+ ```bash
8
+ pip install socket
9
+ ```
10
+
11
+ > **Important:** PyPI package name is `socket`, but to avoid clashing with Python's built-in `socket`
12
+ > (networking) module, **the import name is `socketimport`**:
13
+ > ```python
14
+ > import socketimport as sk
15
+ > ```
16
+
17
+ ## Methods
18
+
19
+ | Method | What it does | Status |
20
+ |---|---|---|
21
+ | **LoRA** (+ rsLoRA, DoRA) | Low-rank addition to weights: `W + (α/r)·BA` | Mature, tested |
22
+ | **ReFT** (LoReFT) | Intervenes in hidden representations, not weights | Mature, tested |
23
+ | **LiteLadder** | Trains a separate "side network" with no backprop to backbone | **Experimental** — validated at small scale, not yet tested with real language data |
24
+ | **GaLore** | Full-parameter training with low-rank gradient projection to reduce optimizer memory | Mature, tested |
25
+
26
+ When to use each method differs: LoRA/ReFT/LiteLadder reduce parameter count (adapter-based),
27
+ while GaLore allows **full-parameter** training but only reduces optimizer memory — they are not
28
+ interchangeable, but complementary tools.
29
+
30
+ ## Quick Start
31
+
32
+ ### LoRA
33
+
34
+ ```python
35
+ import torch
36
+ from socketimport import LoRAAdapter, LoRAConfig
37
+
38
+ model = ... # any nn.Module (e.g., a Llama model)
39
+ config = LoRAConfig(r=16, alpha=32, use_rslora=True, dropout=0.05)
40
+ adapter = LoRAAdapter(model, config)
41
+
42
+ optimizer = torch.optim.AdamW(adapter.trainable_parameters(), lr=1e-4)
43
+ # ... normal training loop, forward with adapter(x) ...
44
+
45
+ adapter.merge() # zero-overhead embedding for inference
46
+ saved = adapter.adapter_state_dict() # only LoRA weights (KB not MB)
47
+ ```
48
+
49
+ Config parameters accept alternative names
50
+ (`rank`, `lora_r`, `lora_alpha`, `dora`, `rslora` etc.) — if conflicting values
51
+ are provided, an error is raised, not silently chosen.
52
+
53
+ ### ReFT
54
+
55
+ ```python
56
+ from socketimport import ReFTAdapter, ReFTConfig
57
+
58
+ # `layers` must be provided explicitly - Socket does not attempt to guess model architecture
59
+ adapter = ReFTAdapter(
60
+ model, layers=model.model.layers, embed_dim=4096,
61
+ config=ReFTConfig(r=4, layers=(8, 16, 24)),
62
+ )
63
+ optimizer = torch.optim.AdamW(adapter.trainable_parameters(), lr=1e-3)
64
+ ```
65
+
66
+ ### LiteLadder (experimental)
67
+
68
+ ```python
69
+ from socketimport import LiteLadderAdapter, LiteLadderConfig
70
+
71
+ adapter = LiteLadderAdapter(
72
+ model, layers=model.model.layers, embed_dim=4096, output_dim=32000,
73
+ config=LiteLadderConfig(side_width=256, rank=32, n_taps=4),
74
+ )
75
+ ```
76
+
77
+ Backward never enters the backbone (showed much lower overhead than LoRA as depth increased in
78
+ small-scale tests) — but this has only been validated on synthetic tasks with a single CPU core.
79
+ **Not recommended** as production default; should be considered an opt-in experimental option.
80
+
81
+ ### GaLore
82
+
83
+ ```python
84
+ from socketimport import GaLoreAdamW, GaLoreConfig, create_galore_param_groups
85
+
86
+ groups = create_galore_param_groups(model, GaLoreConfig(rank=128, update_proj_gap=200))
87
+ optimizer = GaLoreAdamW(groups, lr=1e-4)
88
+ # Model is trained FULL-PARAMETER - no adapter, no merge, GaLore
89
+ # only reduces optimizer memory usage
90
+ ```
91
+
92
+ `GaLoreAdamW` does **not** implement `SocketAdapterBase` — it is not an adapter,
93
+ but a standard `torch.optim.Optimizer` subclass.
94
+
95
+ ## Architecture
96
+
97
+ ```
98
+ socketimport/
99
+ ├── core/
100
+ │ ├── base.py # SocketAdapterBase - shared interface for LoRA/ReFT/LiteLadder
101
+ │ ├── lora.py
102
+ │ ├── reft.py
103
+ │ ├── lite_ladder.py
104
+ │ └── galore.py
105
+ ```
106
+
107
+ All adapter classes (`LoRAAdapter`, `ReFTAdapter`, `LiteLadderAdapter`)
108
+ share the same `SocketAdapterBase` interface: `trainable_parameters()`,
109
+ `merge()`/`unmerge()`, `adapter_state_dict()`/`load_adapter_state_dict()`.
110
+ This allows the training infrastructure (trainer, distributed, profiler) to be
111
+ written independently of which method is selected.
112
+
113
+ ## Development
114
+
115
+ ```bash
116
+ pip install -e ".[dev]"
117
+ pytest tests/ -v
118
+ ```
119
+
120
+ 444 tests covering all modules: mathematical correctness (e.g., zero-initialization as no-op,
121
+ merge/unmerge being inverses), model freezing behavior, end-to-end training actually reducing loss,
122
+ and save/load round-trips.
123
+
124
+ > **Note:** `quantize_linear`/`quantize_model` and their tests require `bitsandbytes`
125
+ > (see [Dependencies](#dependencies)). The `dev` extra installs this automatically; if not installed,
126
+ > quantization tests will fail with `DependencyError` (not a library error).
127
+
128
+ ## Dependencies
129
+
130
+ | Package | Required? | For |
131
+ |---|---|---|
132
+ | `torch>=2.0` | Yes | Entire library |
133
+ | `bitsandbytes>=0.41.0` | No (`pip install socket[quantization]`) | Only `quantize_linear`/`quantize_model` (4-bit/8-bit weight quantization) |
134
+
135
+ All other features (LoRA, ReFT, LiteLadder, GaLore, checkpointing, OOM recovery,
136
+ VRAM guard, distributed backend selection, etc.) work with `torch` alone.
137
+
138
+ ## Limitations (honestly)
139
+
140
+ - All tests run on 1 CPU core with small synthetic tasks — no scale testing on GPU
141
+ or with real language data yet.
142
+ - LiteLadder is not a published method; Socket-specific architecture tested at small scale
143
+ (combination of LST + ReFT-style lightweight interventions).
144
+ - No multi-seed statistical validation; results are single-seed.
145
+
146
+ -Note: PyPI does not normally allow this package name; please use -pip install socket-lm- to install it.
147
+
148
+ ## License
149
+
150
+ MIT — see [LICENSE](LICENSE).
@@ -0,0 +1,37 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61.0"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "socket-lm"
7
+ version = "0.1.0"
8
+ description = "A training-speed-focused LoRA/PEFT library offering four parameter-efficient fine-tuning methods (LoRA, ReFT, LiteLadder, GaLore)"
9
+ readme = "README.md"
10
+ license = { file = "LICENSE" }
11
+ authors = [
12
+ { name = "Omur Bera Isik" },
13
+ ]
14
+ requires-python = ">=3.9"
15
+ dependencies = [
16
+ "torch>=2.0",
17
+ ]
18
+ classifiers = [
19
+ "Development Status :: 3 - Alpha",
20
+ "Intended Audience :: Science/Research",
21
+ "Intended Audience :: Developers",
22
+ "License :: OSI Approved :: MIT License",
23
+ "Programming Language :: Python :: 3",
24
+ "Programming Language :: Python :: 3.9",
25
+ "Programming Language :: Python :: 3.10",
26
+ "Programming Language :: Python :: 3.11",
27
+ "Programming Language :: Python :: 3.12",
28
+ "Topic :: Scientific/Engineering :: Artificial Intelligence",
29
+ ]
30
+ keywords = ["lora", "peft", "fine-tuning", "pytorch", "llm", "deep-learning"]
31
+
32
+ [project.optional-dependencies]
33
+ quantization = ["bitsandbytes>=0.41.0"]
34
+ dev = ["pytest>=7.0", "bitsandbytes>=0.41.0"]
35
+
36
+ [tool.setuptools.packages.find]
37
+ include = ["socketimport*"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,199 @@
1
+ Metadata-Version: 2.4
2
+ Name: socket-lm
3
+ Version: 0.1.0
4
+ Summary: A training-speed-focused LoRA/PEFT library offering four parameter-efficient fine-tuning methods (LoRA, ReFT, LiteLadder, GaLore)
5
+ Author: Omur Bera Isik
6
+ License: MIT License
7
+
8
+ Copyright (c) 2026 Ömür Bera Işık
9
+
10
+ Permission is hereby granted, free of charge, to any person obtaining a copy
11
+ of this software and associated documentation files (the "Software"), to deal
12
+ in the Software without restriction, including without limitation the rights
13
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
+ copies of the Software, and to permit persons to whom the Software is
15
+ furnished to do so, subject to the following conditions:
16
+
17
+ The above copyright notice and this permission notice shall be included in all
18
+ copies or substantial portions of the Software.
19
+
20
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
+ SOFTWARE.
27
+
28
+ Keywords: lora,peft,fine-tuning,pytorch,llm,deep-learning
29
+ Classifier: Development Status :: 3 - Alpha
30
+ Classifier: Intended Audience :: Science/Research
31
+ Classifier: Intended Audience :: Developers
32
+ Classifier: License :: OSI Approved :: MIT License
33
+ Classifier: Programming Language :: Python :: 3
34
+ Classifier: Programming Language :: Python :: 3.9
35
+ Classifier: Programming Language :: Python :: 3.10
36
+ Classifier: Programming Language :: Python :: 3.11
37
+ Classifier: Programming Language :: Python :: 3.12
38
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
39
+ Requires-Python: >=3.9
40
+ Description-Content-Type: text/markdown
41
+ License-File: LICENSE
42
+ Requires-Dist: torch>=2.0
43
+ Provides-Extra: quantization
44
+ Requires-Dist: bitsandbytes>=0.41.0; extra == "quantization"
45
+ Provides-Extra: dev
46
+ Requires-Dist: pytest>=7.0; extra == "dev"
47
+ Requires-Dist: bitsandbytes>=0.41.0; extra == "dev"
48
+ Dynamic: license-file
49
+
50
+ # Socket
51
+
52
+ A LoRA/PEFT library focused on training speed. Offers four different parameter-efficient
53
+ fine-tuning methods — all written from scratch with no dependency on external PEFT libraries
54
+ (`peft` etc.).
55
+
56
+ ```bash
57
+ pip install socket
58
+ ```
59
+
60
+ > **Important:** PyPI package name is `socket`, but to avoid clashing with Python's built-in `socket`
61
+ > (networking) module, **the import name is `socketimport`**:
62
+ > ```python
63
+ > import socketimport as sk
64
+ > ```
65
+
66
+ ## Methods
67
+
68
+ | Method | What it does | Status |
69
+ |---|---|---|
70
+ | **LoRA** (+ rsLoRA, DoRA) | Low-rank addition to weights: `W + (α/r)·BA` | Mature, tested |
71
+ | **ReFT** (LoReFT) | Intervenes in hidden representations, not weights | Mature, tested |
72
+ | **LiteLadder** | Trains a separate "side network" with no backprop to backbone | **Experimental** — validated at small scale, not yet tested with real language data |
73
+ | **GaLore** | Full-parameter training with low-rank gradient projection to reduce optimizer memory | Mature, tested |
74
+
75
+ When to use each method differs: LoRA/ReFT/LiteLadder reduce parameter count (adapter-based),
76
+ while GaLore allows **full-parameter** training but only reduces optimizer memory — they are not
77
+ interchangeable, but complementary tools.
78
+
79
+ ## Quick Start
80
+
81
+ ### LoRA
82
+
83
+ ```python
84
+ import torch
85
+ from socketimport import LoRAAdapter, LoRAConfig
86
+
87
+ model = ... # any nn.Module (e.g., a Llama model)
88
+ config = LoRAConfig(r=16, alpha=32, use_rslora=True, dropout=0.05)
89
+ adapter = LoRAAdapter(model, config)
90
+
91
+ optimizer = torch.optim.AdamW(adapter.trainable_parameters(), lr=1e-4)
92
+ # ... normal training loop, forward with adapter(x) ...
93
+
94
+ adapter.merge() # zero-overhead embedding for inference
95
+ saved = adapter.adapter_state_dict() # only LoRA weights (KB not MB)
96
+ ```
97
+
98
+ Config parameters accept alternative names
99
+ (`rank`, `lora_r`, `lora_alpha`, `dora`, `rslora` etc.) — if conflicting values
100
+ are provided, an error is raised, not silently chosen.
101
+
102
+ ### ReFT
103
+
104
+ ```python
105
+ from socketimport import ReFTAdapter, ReFTConfig
106
+
107
+ # `layers` must be provided explicitly - Socket does not attempt to guess model architecture
108
+ adapter = ReFTAdapter(
109
+ model, layers=model.model.layers, embed_dim=4096,
110
+ config=ReFTConfig(r=4, layers=(8, 16, 24)),
111
+ )
112
+ optimizer = torch.optim.AdamW(adapter.trainable_parameters(), lr=1e-3)
113
+ ```
114
+
115
+ ### LiteLadder (experimental)
116
+
117
+ ```python
118
+ from socketimport import LiteLadderAdapter, LiteLadderConfig
119
+
120
+ adapter = LiteLadderAdapter(
121
+ model, layers=model.model.layers, embed_dim=4096, output_dim=32000,
122
+ config=LiteLadderConfig(side_width=256, rank=32, n_taps=4),
123
+ )
124
+ ```
125
+
126
+ Backward never enters the backbone (showed much lower overhead than LoRA as depth increased in
127
+ small-scale tests) — but this has only been validated on synthetic tasks with a single CPU core.
128
+ **Not recommended** as production default; should be considered an opt-in experimental option.
129
+
130
+ ### GaLore
131
+
132
+ ```python
133
+ from socketimport import GaLoreAdamW, GaLoreConfig, create_galore_param_groups
134
+
135
+ groups = create_galore_param_groups(model, GaLoreConfig(rank=128, update_proj_gap=200))
136
+ optimizer = GaLoreAdamW(groups, lr=1e-4)
137
+ # Model is trained FULL-PARAMETER - no adapter, no merge, GaLore
138
+ # only reduces optimizer memory usage
139
+ ```
140
+
141
+ `GaLoreAdamW` does **not** implement `SocketAdapterBase` — it is not an adapter,
142
+ but a standard `torch.optim.Optimizer` subclass.
143
+
144
+ ## Architecture
145
+
146
+ ```
147
+ socketimport/
148
+ ├── core/
149
+ │ ├── base.py # SocketAdapterBase - shared interface for LoRA/ReFT/LiteLadder
150
+ │ ├── lora.py
151
+ │ ├── reft.py
152
+ │ ├── lite_ladder.py
153
+ │ └── galore.py
154
+ ```
155
+
156
+ All adapter classes (`LoRAAdapter`, `ReFTAdapter`, `LiteLadderAdapter`)
157
+ share the same `SocketAdapterBase` interface: `trainable_parameters()`,
158
+ `merge()`/`unmerge()`, `adapter_state_dict()`/`load_adapter_state_dict()`.
159
+ This allows the training infrastructure (trainer, distributed, profiler) to be
160
+ written independently of which method is selected.
161
+
162
+ ## Development
163
+
164
+ ```bash
165
+ pip install -e ".[dev]"
166
+ pytest tests/ -v
167
+ ```
168
+
169
+ 444 tests covering all modules: mathematical correctness (e.g., zero-initialization as no-op,
170
+ merge/unmerge being inverses), model freezing behavior, end-to-end training actually reducing loss,
171
+ and save/load round-trips.
172
+
173
+ > **Note:** `quantize_linear`/`quantize_model` and their tests require `bitsandbytes`
174
+ > (see [Dependencies](#dependencies)). The `dev` extra installs this automatically; if not installed,
175
+ > quantization tests will fail with `DependencyError` (not a library error).
176
+
177
+ ## Dependencies
178
+
179
+ | Package | Required? | For |
180
+ |---|---|---|
181
+ | `torch>=2.0` | Yes | Entire library |
182
+ | `bitsandbytes>=0.41.0` | No (`pip install socket[quantization]`) | Only `quantize_linear`/`quantize_model` (4-bit/8-bit weight quantization) |
183
+
184
+ All other features (LoRA, ReFT, LiteLadder, GaLore, checkpointing, OOM recovery,
185
+ VRAM guard, distributed backend selection, etc.) work with `torch` alone.
186
+
187
+ ## Limitations (honestly)
188
+
189
+ - All tests run on 1 CPU core with small synthetic tasks — no scale testing on GPU
190
+ or with real language data yet.
191
+ - LiteLadder is not a published method; Socket-specific architecture tested at small scale
192
+ (combination of LST + ReFT-style lightweight interventions).
193
+ - No multi-seed statistical validation; results are single-seed.
194
+
195
+ -Note: PyPI does not normally allow this package name; please use -pip install socket-lm- to install it.
196
+
197
+ ## License
198
+
199
+ MIT — see [LICENSE](LICENSE).
@@ -0,0 +1,76 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ socket_lm.egg-info/PKG-INFO
5
+ socket_lm.egg-info/SOURCES.txt
6
+ socket_lm.egg-info/dependency_links.txt
7
+ socket_lm.egg-info/requires.txt
8
+ socket_lm.egg-info/top_level.txt
9
+ socketimport/__init__.py
10
+ socketimport/config.py
11
+ socketimport/deps.py
12
+ socketimport/device.py
13
+ socketimport/errors.py
14
+ socketimport/utils.py
15
+ socketimport/core/__init__.py
16
+ socketimport/core/accelerator.py
17
+ socketimport/core/attention.py
18
+ socketimport/core/base.py
19
+ socketimport/core/galore.py
20
+ socketimport/core/lite_ladder.py
21
+ socketimport/core/lora.py
22
+ socketimport/core/model_loader.py
23
+ socketimport/core/quantization.py
24
+ socketimport/core/reft.py
25
+ socketimport/data/__init__.py
26
+ socketimport/data/loader.py
27
+ socketimport/distributed/__init__.py
28
+ socketimport/memory/__init__.py
29
+ socketimport/memory/batch_finder.py
30
+ socketimport/memory/checkpointing.py
31
+ socketimport/memory/tracker.py
32
+ socketimport/optim/__init__.py
33
+ socketimport/optim/ema.py
34
+ socketimport/optim/fused.py
35
+ socketimport/optim/lion.py
36
+ socketimport/optim/scheduler.py
37
+ socketimport/optim/swa.py
38
+ socketimport/profiler/__init__.py
39
+ socketimport/profiler/benchmark.py
40
+ socketimport/profiler/trace.py
41
+ socketimport/training/__init__.py
42
+ socketimport/training/callbacks.py
43
+ socketimport/training/framework_adapter.py
44
+ socketimport/training/oom_recovery.py
45
+ socketimport/training/trainer.py
46
+ socketimport/training/vram_guard.py
47
+ tests/test_accelerator.py
48
+ tests/test_attention.py
49
+ tests/test_batch_finder.py
50
+ tests/test_benchmark.py
51
+ tests/test_callbacks.py
52
+ tests/test_checkpointing.py
53
+ tests/test_config.py
54
+ tests/test_deps.py
55
+ tests/test_device.py
56
+ tests/test_distributed.py
57
+ tests/test_ema.py
58
+ tests/test_errors.py
59
+ tests/test_framework_adapter.py
60
+ tests/test_fused.py
61
+ tests/test_galore.py
62
+ tests/test_lion.py
63
+ tests/test_lite_ladder.py
64
+ tests/test_loader.py
65
+ tests/test_lora.py
66
+ tests/test_model_loader.py
67
+ tests/test_oom_recovery.py
68
+ tests/test_quantization.py
69
+ tests/test_reft.py
70
+ tests/test_scheduler.py
71
+ tests/test_swa.py
72
+ tests/test_trace.py
73
+ tests/test_tracker.py
74
+ tests/test_trainer.py
75
+ tests/test_utils.py
76
+ tests/test_vram_guard.py