Skip to content

Commit 02e4c99

Browse files
[#259] clippy
1 parent 243414c commit 02e4c99

4 files changed

Lines changed: 52 additions & 28 deletions

File tree

src/bin/orangu-gguf/model.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1573,21 +1573,21 @@ mod tests {
15731573
for j in 0..2 {
15741574
let at = i + j * LANES;
15751575
let weight = load8(&b[at..]);
1576-
for (r, row) in rows.iter().enumerate() {
1577-
acc[r][j] = load8(&row[at..]).mul_add(weight, acc[r][j]);
1576+
for (row, sums) in rows.iter().zip(acc.iter_mut()) {
1577+
sums[j] = load8(&row[at..]).mul_add(weight, sums[j]);
15781578
}
15791579
}
15801580
i += 2 * LANES;
15811581
}
15821582
let mut out = [0f32; 4];
1583-
for (r, row) in rows.iter().enumerate() {
1584-
let mut sum = horizontal(acc[r][0] + acc[r][1]);
1583+
for ((value, row), sums) in out.iter_mut().zip(rows.iter()).zip(acc.iter()) {
1584+
let mut sum = horizontal(sums[0] + sums[1]);
15851585
let mut at = i;
15861586
while at < b.len() {
15871587
sum += row[at] * b[at];
15881588
at += 1;
15891589
}
1590-
out[r] = sum;
1590+
*value = sum;
15911591
}
15921592
out
15931593
}
@@ -1647,7 +1647,7 @@ mod tests {
16471647
}
16481648
}
16491649

1650-
fn matmul_blocked8(y: &mut [f32], x: &[f32], w: &[f32], t: usize, k: usize, n: usize) {
1650+
fn matmul_blocked8(y: &mut [f32], x: &[f32], w: &[f32], k: usize, n: usize) {
16511651
y.par_chunks_mut(n * TILE)
16521652
.zip(x.par_chunks(k * TILE))
16531653
.for_each(|(out_tile, in_tile)| tile_blocked8(out_tile, in_tile, w, k, n));
@@ -1678,7 +1678,7 @@ mod tests {
16781678
}
16791679
}
16801680

1681-
fn matmul_blocked(y: &mut [f32], x: &[f32], w: &[f32], t: usize, k: usize, n: usize) {
1681+
fn matmul_blocked(y: &mut [f32], x: &[f32], w: &[f32], k: usize, n: usize) {
16821682
y.par_chunks_mut(n * TILE)
16831683
.zip(x.par_chunks(k * TILE))
16841684
.for_each(|(out_tile, in_tile)| tile_blocked(out_tile, in_tile, w, k, n));
@@ -1831,18 +1831,18 @@ mod tests {
18311831
}
18321832
let plain = flop * passes as f64 / start.elapsed().as_secs_f64() / 1e9;
18331833

1834-
matmul_blocked(&mut y, &x, &w, t, k, n);
1834+
matmul_blocked(&mut y, &x, &w, k, n);
18351835
let start = std::time::Instant::now();
18361836
for _ in 0..passes {
1837-
matmul_blocked(&mut y, &x, &w, t, k, n);
1837+
matmul_blocked(&mut y, &x, &w, k, n);
18381838
}
18391839
let four = flop * passes as f64 / start.elapsed().as_secs_f64() / 1e9;
18401840
let error4 = relative(&reference, &y);
18411841

1842-
matmul_blocked8(&mut y, &x, &w, t, k, n);
1842+
matmul_blocked8(&mut y, &x, &w, k, n);
18431843
let start = std::time::Instant::now();
18441844
for _ in 0..passes {
1845-
matmul_blocked8(&mut y, &x, &w, t, k, n);
1845+
matmul_blocked8(&mut y, &x, &w, k, n);
18461846
}
18471847
let eight = flop * passes as f64 / start.elapsed().as_secs_f64() / 1e9;
18481848
let error8 = relative(&reference, &y);

src/bin/orangu-gguf/pack.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,10 @@ impl Tokens {
167167
pub fn window(&self, offset: usize, count: usize) -> Vec<u32> {
168168
let bytes = &self.map[offset * 4..(offset + count) * 4];
169169
bytes
170-
.chunks_exact(4)
171-
.map(|b| u32::from_le_bytes([b[0], b[1], b[2], b[3]]))
170+
.as_chunks::<4>()
171+
.0
172+
.iter()
173+
.map(|b| u32::from_le_bytes(*b))
172174
.collect()
173175
}
174176
}

src/bin/orangu-gguf/quant.rs

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1460,19 +1460,25 @@ fn fit_signed_scale(x: &[f32], nmax: i32, quants: &mut [i8]) -> f32 {
14601460
pub fn decode(ggml_type: u32, bytes: &[u8], elements: usize) -> Result<Vec<f32>> {
14611461
match ggml_type {
14621462
GGML_TYPE_F32 => Ok(bytes
1463-
.chunks_exact(4)
1463+
.as_chunks::<4>()
1464+
.0
1465+
.iter()
14641466
.take(elements)
1465-
.map(|b| f32::from_le_bytes([b[0], b[1], b[2], b[3]]))
1467+
.map(|b| f32::from_le_bytes(*b))
14661468
.collect()),
14671469
GGML_TYPE_F16 => Ok(bytes
1468-
.chunks_exact(2)
1470+
.as_chunks::<2>()
1471+
.0
1472+
.iter()
14691473
.take(elements)
1470-
.map(|b| f16::from_le_bytes([b[0], b[1]]).to_f32())
1474+
.map(|b| f16::from_le_bytes(*b).to_f32())
14711475
.collect()),
14721476
GGML_TYPE_BF16 => Ok(bytes
1473-
.chunks_exact(2)
1477+
.as_chunks::<2>()
1478+
.0
1479+
.iter()
14741480
.take(elements)
1475-
.map(|b| f32::from_bits((u16::from_le_bytes([b[0], b[1]]) as u32) << 16))
1481+
.map(|b| f32::from_bits((u16::from_le_bytes(*b) as u32) << 16))
14761482
.collect()),
14771483
other => bail!(
14781484
"this file's tensors are already {} — quantize from the F32, F16 or BF16 file instead",
@@ -1491,7 +1497,9 @@ mod tests {
14911497
fn dequantize(ggml_type: u32, bytes: &[u8], elements: usize) -> Vec<f32> {
14921498
match ggml_type {
14931499
GGML_TYPE_Q2_K => bytes
1494-
.chunks_exact(QK_K / 16 + QK_K / 4 + 4)
1500+
.as_chunks::<{ QK_K / 16 + QK_K / 4 + 4 }>()
1501+
.0
1502+
.iter()
14951503
.flat_map(|block| {
14961504
let scales = &block[..QK_K / 16];
14971505
let quants = &block[QK_K / 16..QK_K / 16 + QK_K / 4];
@@ -1509,7 +1517,9 @@ mod tests {
15091517
.take(elements)
15101518
.collect(),
15111519
GGML_TYPE_Q3_K => bytes
1512-
.chunks_exact(QK_K / 8 + QK_K / 4 + 12 + 2)
1520+
.as_chunks::<{ QK_K / 8 + QK_K / 4 + 12 + 2 }>()
1521+
.0
1522+
.iter()
15131523
.flat_map(|block| {
15141524
let mask = &block[..QK_K / 8];
15151525
let quants = &block[QK_K / 8..QK_K / 8 + QK_K / 4];
@@ -1529,7 +1539,9 @@ mod tests {
15291539
.take(elements)
15301540
.collect(),
15311541
GGML_TYPE_Q5_K => bytes
1532-
.chunks_exact(2 + 2 + 12 + QK_K / 8 + QK_K / 2)
1542+
.as_chunks::<{ 2 + 2 + 12 + QK_K / 8 + QK_K / 2 }>()
1543+
.0
1544+
.iter()
15331545
.flat_map(|block| {
15341546
let d = f16::from_le_bytes([block[0], block[1]]).to_f32();
15351547
let dmin = f16::from_le_bytes([block[2], block[3]]).to_f32();
@@ -1552,7 +1564,9 @@ mod tests {
15521564
.take(elements)
15531565
.collect(),
15541566
GGML_TYPE_IQ4_NL => bytes
1555-
.chunks_exact(2 + QK / 2)
1567+
.as_chunks::<{ 2 + QK / 2 }>()
1568+
.0
1569+
.iter()
15561570
.flat_map(|block| {
15571571
let d = f16::from_le_bytes([block[0], block[1]]).to_f32();
15581572
let quants = &block[2..];
@@ -1565,7 +1579,9 @@ mod tests {
15651579
.take(elements)
15661580
.collect(),
15671581
GGML_TYPE_IQ4_XS => bytes
1568-
.chunks_exact(2 + 2 + QK_K / 64 + QK_K / 2)
1582+
.as_chunks::<{ 2 + 2 + QK_K / 64 + QK_K / 2 }>()
1583+
.0
1584+
.iter()
15691585
.flat_map(|block| {
15701586
let d = f16::from_le_bytes([block[0], block[1]]).to_f32();
15711587
let scales_h = u16::from_le_bytes([block[2], block[3]]);
@@ -1589,7 +1605,9 @@ mod tests {
15891605
.take(elements)
15901606
.collect(),
15911607
GGML_TYPE_Q4_K => bytes
1592-
.chunks_exact(2 + 2 + 12 + QK_K / 2)
1608+
.as_chunks::<{ 2 + 2 + 12 + QK_K / 2 }>()
1609+
.0
1610+
.iter()
15931611
.flat_map(|block| {
15941612
let d = f16::from_le_bytes([block[0], block[1]]).to_f32();
15951613
let dmin = f16::from_le_bytes([block[2], block[3]]).to_f32();
@@ -1609,7 +1627,9 @@ mod tests {
16091627
.take(elements)
16101628
.collect(),
16111629
GGML_TYPE_Q6_K => bytes
1612-
.chunks_exact(QK_K / 2 + QK_K / 4 + QK_K / 16 + 2)
1630+
.as_chunks::<{ QK_K / 2 + QK_K / 4 + QK_K / 16 + 2 }>()
1631+
.0
1632+
.iter()
16131633
.flat_map(|block| {
16141634
let low = &block[..QK_K / 2];
16151635
let high = &block[QK_K / 2..QK_K / 2 + QK_K / 4];

src/bin/orangu-gguf/train.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -570,8 +570,10 @@ fn read_floats(input: &mut impl Read) -> Result<Vec<f32>> {
570570
input.read_exact(&mut buffer[..take * 4])?;
571571
values.extend(
572572
buffer[..take * 4]
573-
.chunks_exact(4)
574-
.map(|b| f32::from_le_bytes([b[0], b[1], b[2], b[3]])),
573+
.as_chunks::<4>()
574+
.0
575+
.iter()
576+
.map(|b| f32::from_le_bytes(*b)),
575577
);
576578
left -= take;
577579
}

0 commit comments

Comments
 (0)