|
1 | 1 | use crate::{Operators, Weights}; |
2 | | -use clip::{ClipArgs, ClipMeta, ClipStorage, ClipWorker, Image}; |
3 | | -use gguf::GGufModel; |
4 | | -use operators::common_cpu::{Cpu, ThisThread}; |
| 2 | +use clip::{ClipArgs, ClipMeta, ClipStorage, ClipWorker, Image, Tensor}; |
| 3 | +use gguf::{ggml_quants::digit_layout::types as ty, GGufModel}; |
| 4 | +use operators::{ |
| 5 | + common_cpu::{Cpu, ThisThread}, |
| 6 | + Blob, |
| 7 | +}; |
5 | 8 | use std::time::Instant; |
6 | 9 | use test_utils::Inference; |
7 | 10 |
|
@@ -50,21 +53,51 @@ fn test_infer() { |
50 | 53 | .launch( |
51 | 54 | ClipArgs { |
52 | 55 | raw: whole.to_nchw(), |
| 56 | + pos: pos70(whole.shape(), d_patch).map_slice(), |
53 | 57 | }, |
54 | 58 | &mut [], |
55 | 59 | &ThisThread, |
56 | 60 | ) |
57 | 61 | .unwrap(); |
58 | 62 |
|
59 | 63 | if let Some(patches) = slices.patches_nchw() { |
| 64 | + let &[_, 3, h, w] = patches.shape() else { |
| 65 | + unreachable!() |
| 66 | + }; |
60 | 67 | worker |
61 | 68 | .launch( |
62 | 69 | ClipArgs { |
63 | 70 | raw: patches.map_slice(), |
| 71 | + pos: pos70([w, h], d_patch).map_slice(), |
64 | 72 | }, |
65 | 73 | &mut [], |
66 | 74 | &ThisThread, |
67 | 75 | ) |
68 | 76 | .unwrap(); |
69 | 77 | } |
70 | 78 | } |
| 79 | + |
| 80 | +fn pos70([w, h]: [usize; 2], d_patch: usize) -> Tensor<Blob> { |
| 81 | + let pos_w = w / d_patch; |
| 82 | + let pos_h = h / d_patch; |
| 83 | + let mut bucket_corrds_h = [0; 70]; |
| 84 | + let mut bucket_corrds_w = [0; 70]; |
| 85 | + for i in 0..pos_w { |
| 86 | + bucket_corrds_w[i] = ((70 * i) as f64 / pos_w as f64) as _; |
| 87 | + } |
| 88 | + for i in 0..pos_h { |
| 89 | + bucket_corrds_h[i] = ((70 * i) as f64 / pos_h as f64) as _; |
| 90 | + } |
| 91 | + |
| 92 | + let mut ans = Tensor::new(ty::U32, &[pos_w * pos_h]).map(Blob::new); |
| 93 | + let (&mut [], data, &mut []) = (unsafe { ans.get_mut().align_to_mut::<u32>() }) else { |
| 94 | + panic!() |
| 95 | + }; |
| 96 | + |
| 97 | + let f = |i, d| ((70 * i) as f64 / d as f64) as u32; |
| 98 | + for i in 0..pos_h * pos_w { |
| 99 | + data[i] = f(i / pos_w, pos_h) * 70 + f(i % pos_w, pos_w); |
| 100 | + } |
| 101 | + |
| 102 | + ans |
| 103 | +} |
0 commit comments