torobi 0.1.0 → 0.1.1
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +11 -0
- data/Cargo.lock +2 -2
- data/README.md +1 -1
- data/engine/Cargo.toml +1 -1
- data/engine/src/init.rs +40 -4
- data/ext/torobi/Cargo.toml +1 -1
- data/lib/torobi/lora.rb +3 -1
- data/lib/torobi/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 1448cb17c9a5cf11d43f8ec38d413f05dc2298128b39670e5423d7ca34bf4a73
|
|
4
|
+
data.tar.gz: 37e007325bd7ce3e6584943e086c7ccf189602f5f2302c3a7f4daab481347519
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d30b0e98e4f19cb17f401884d4b63e828bac6c6b8e525bfd628524c4dbc2ad88d0435b508cf39417d72a742d90b9508c5fcac14feedbde19197a27e3a6b9db47
|
|
7
|
+
data.tar.gz: 1f7e60d6a8a9ab1fff815a1bb0256b1050dd981e490b49f6225c236741285cf206fd603cbae89dcad0e8e51cf0535e168009468ec5044f05cf7c244e3aa13b43
|
data/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,17 @@ What changed, for somebody deciding whether to upgrade.
|
|
|
4
4
|
|
|
5
5
|
## Unreleased
|
|
6
6
|
|
|
7
|
+
## 0.1.1 - 2026-12-02
|
|
8
|
+
|
|
9
|
+
- A parameter declared `kaiming_uniform` (a LoRA's A, a `linear` that no
|
|
10
|
+
file holds) is drawn within 1 / sqrt(fan_in), as PyTorch's `Linear`,
|
|
11
|
+
PEFT and mlx-lm draw it, not sqrt(6 / fan_in). A LoRA A 2.45 times as
|
|
12
|
+
wide made the adapter's update B A as much larger, much as a learning
|
|
13
|
+
rate 2.45 times as high would: Qwen2.5-0.5B's LoRA run with PEFT's
|
|
14
|
+
defaults ended at a mean loss of 1.107 here against PEFT's 1.385, and at
|
|
15
|
+
1.116 on PEFT with its A drawn as wide. A checkpoint taken before this
|
|
16
|
+
resumes as before (its A is in the file), but a new run starts elsewhere.
|
|
17
|
+
|
|
7
18
|
## 0.1.0 - 2026-11-30
|
|
8
19
|
|
|
9
20
|
The first release: a training framework for Ruby that describes a model
|
data/Cargo.lock
CHANGED
|
@@ -477,7 +477,7 @@ dependencies = [
|
|
|
477
477
|
|
|
478
478
|
[[package]]
|
|
479
479
|
name = "torobi"
|
|
480
|
-
version = "0.1.
|
|
480
|
+
version = "0.1.1"
|
|
481
481
|
dependencies = [
|
|
482
482
|
"anyhow",
|
|
483
483
|
"magnus",
|
|
@@ -488,7 +488,7 @@ dependencies = [
|
|
|
488
488
|
|
|
489
489
|
[[package]]
|
|
490
490
|
name = "torobi-engine"
|
|
491
|
-
version = "0.1.
|
|
491
|
+
version = "0.1.1"
|
|
492
492
|
dependencies = [
|
|
493
493
|
"anyhow",
|
|
494
494
|
"bindgen",
|
data/README.md
CHANGED
|
@@ -240,7 +240,7 @@ only a window of the recent past. It declares exactly what gemma-3-270m
|
|
|
240
240
|
holds, and its numbers agree with transformers as closely as the family
|
|
241
241
|
above does.
|
|
242
242
|
|
|
243
|
-
The version is 0.1.
|
|
243
|
+
The version is 0.1.1 and the API still moves.
|
|
244
244
|
|
|
245
245
|
## License
|
|
246
246
|
|
data/engine/Cargo.toml
CHANGED
data/engine/src/init.rs
CHANGED
|
@@ -37,9 +37,13 @@ pub fn build(spec: &ParameterSpec, key: &Array) -> Result<Array> {
|
|
|
37
37
|
let std = number(spec, "std").unwrap_or(0.02);
|
|
38
38
|
crate::mlxc::random::normal::<f32>(shape, 0.0, std, key)?
|
|
39
39
|
}
|
|
40
|
-
// Kaiming uniform as PyTorch's `Linear` uses it
|
|
41
|
-
// sqrt(
|
|
42
|
-
// last dimension of a [out, in] weight.
|
|
40
|
+
// Kaiming uniform as PyTorch's `Linear` uses it
|
|
41
|
+
// (`kaiming_uniform_(w, a=sqrt(5))`): bound 1 / sqrt(fan_in),
|
|
42
|
+
// where fan_in is the last dimension of a [out, in] weight. PEFT
|
|
43
|
+
// starts a LoRA A the same way and mlx-lm with the same bound, so
|
|
44
|
+
// an adapter trained here starts where theirs do. (Kaiming's own
|
|
45
|
+
// default, a = 0, gives sqrt(6 / fan_in), 2.45 times as wide: an
|
|
46
|
+
// A that wide trains as if at 2.45 times the learning rate.)
|
|
43
47
|
"kaiming_uniform" => {
|
|
44
48
|
let fan_in = *shape.last().with_context(|| {
|
|
45
49
|
format!("parameter {:?}: kaiming_uniform wants a shape", spec.path)
|
|
@@ -49,7 +53,7 @@ pub fn build(spec: &ParameterSpec, key: &Array) -> Result<Array> {
|
|
|
49
53
|
"parameter {:?}: kaiming_uniform wants a positive last dimension",
|
|
50
54
|
spec.path
|
|
51
55
|
);
|
|
52
|
-
let bound =
|
|
56
|
+
let bound = fan_in.sqrt().recip();
|
|
53
57
|
crate::mlxc::random::uniform::<f32>(-bound, bound, shape, key)?
|
|
54
58
|
}
|
|
55
59
|
other => anyhow::bail!(
|
|
@@ -63,3 +67,35 @@ pub fn build(spec: &ParameterSpec, key: &Array) -> Result<Array> {
|
|
|
63
67
|
fn number(spec: &ParameterSpec, key: &str) -> Option<f32> {
|
|
64
68
|
spec.initializer.get(key).and_then(Value::as_f64).map(|v| v as f32)
|
|
65
69
|
}
|
|
70
|
+
|
|
71
|
+
#[cfg(test)]
|
|
72
|
+
mod tests {
|
|
73
|
+
use super::*;
|
|
74
|
+
|
|
75
|
+
/// A LoRA A on Qwen2.5-0.5B's width fills the bound PyTorch's `Linear`
|
|
76
|
+
/// and PEFT draw from, 1 / sqrt(896), and goes no further.
|
|
77
|
+
#[test]
|
|
78
|
+
fn kaiming_uniform_draws_within_one_over_the_root_of_fan_in() {
|
|
79
|
+
crate::runtime::runtime()
|
|
80
|
+
.execute(|| {
|
|
81
|
+
let mut initializer = serde_json::Map::new();
|
|
82
|
+
initializer.insert("type".into(), "kaiming_uniform".into());
|
|
83
|
+
let spec = ParameterSpec {
|
|
84
|
+
path: "a".into(),
|
|
85
|
+
shape: vec![8, 896],
|
|
86
|
+
dtype: "float32".into(),
|
|
87
|
+
initializer,
|
|
88
|
+
trainable: true,
|
|
89
|
+
};
|
|
90
|
+
let drawn = build(&spec, &crate::mlxc::random::key(42)?)?;
|
|
91
|
+
drawn.eval()?;
|
|
92
|
+
let widest = drawn.as_slice::<f32>()?.iter().fold(0.0f32, |m, v| m.max(v.abs()));
|
|
93
|
+
let bound = 1.0 / 896f32.sqrt();
|
|
94
|
+
assert!(widest <= bound, "{widest} is outside +-{bound}");
|
|
95
|
+
// (7168 draws: the widest comes within 1% of the bound)
|
|
96
|
+
assert!(widest > 0.99 * bound, "{widest} does not reach +-{bound}");
|
|
97
|
+
Ok(())
|
|
98
|
+
})
|
|
99
|
+
.unwrap();
|
|
100
|
+
}
|
|
101
|
+
}
|
data/ext/torobi/Cargo.toml
CHANGED
data/lib/torobi/lora.rb
CHANGED
|
@@ -106,7 +106,9 @@ module Torobi
|
|
|
106
106
|
# narrowed back to `x`'s dtype on the way out, so the layers around
|
|
107
107
|
# it are as they were. They are the only parameters that train, and
|
|
108
108
|
# bf16 holds a value to about 0.4%: an Adam step of 1e-4 on an entry
|
|
109
|
-
# of A near 0.
|
|
109
|
+
# of A near 0.02 (A starts within 1 / sqrt(d_in), 0.033 for 896) is
|
|
110
|
+
# a change of 0.5%, which bf16 rounds to a whole step of its own or
|
|
111
|
+
# away. mlx-lm makes
|
|
110
112
|
# the same choice (`tuner/lora.py`: its matrices are made in MLX's
|
|
111
113
|
# default f32 and the result is `astype(x.dtype)`). On an f32 model
|
|
112
114
|
# neither cast is a node, and nothing changes.
|
data/lib/torobi/version.rb
CHANGED