Upload shenava_tract_streaming.patch with huggingface_hub
Browse files
shenava_tract_streaming.patch
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
diff --git a/onnx/src/ops/cast.rs b/onnx/src/ops/cast.rs
|
| 2 |
+
index f63e483..7ad2471 100644
|
| 3 |
+
--- a/onnx/src/ops/cast.rs
|
| 4 |
+
+++ b/onnx/src/ops/cast.rs
|
| 5 |
+
@@ -66,7 +66,7 @@ impl ElementWiseMiniOp for Cast {
|
| 6 |
+
node: &TypedNode,
|
| 7 |
+
) -> TractResult<Option<TypedModelPatch>> {
|
| 8 |
+
let from = model.outlet_fact(node.inputs[0])?.datum_type;
|
| 9 |
+
- if from == self.to || (from == TDim::datum_type() && self.to == i32::datum_type()) {
|
| 10 |
+
+ if from == self.to {
|
| 11 |
+
Ok(Some(TypedModelPatch::replace_single_op(model, node, &node.inputs, Identity)?))
|
| 12 |
+
} else if from == String::datum_type() && self.to == f32::datum_type() {
|
| 13 |
+
Ok(None)
|
| 14 |
+
diff --git a/onnx/src/ops/math/clip.rs b/onnx/src/ops/math/clip.rs
|
| 15 |
+
index 5fe33d5..0a240e5 100644
|
| 16 |
+
--- a/onnx/src/ops/math/clip.rs
|
| 17 |
+
+++ b/onnx/src/ops/math/clip.rs
|
| 18 |
+
@@ -54,12 +54,8 @@ impl Expansion for Clip11 {
|
| 19 |
+
1 + self.input_min.is_some() as usize + self.input_max.is_some() as usize,
|
| 20 |
+
)?;
|
| 21 |
+
check_output_arity(outputs, 1)?;
|
| 22 |
+
- if let Some(input) = self.input_min {
|
| 23 |
+
- s.equals(&inputs[0].datum_type, &inputs[input].datum_type)?;
|
| 24 |
+
- }
|
| 25 |
+
- if let Some(input) = self.input_max {
|
| 26 |
+
- s.equals(&inputs[0].datum_type, &inputs[input].datum_type)?;
|
| 27 |
+
- }
|
| 28 |
+
+ // Relaxed for streaming cache-len clamps: bounds may be I64 constants while the
|
| 29 |
+
+ // clamped value is a symbolic TDim. wire() casts the bounds to the input dtype.
|
| 30 |
+
s.equals(&inputs[0].datum_type, &outputs[0].datum_type)?;
|
| 31 |
+
s.equals(&inputs[0].shape, &outputs[0].shape)?;
|
| 32 |
+
Ok(())
|
| 33 |
+
@@ -71,21 +67,30 @@ impl Expansion for Clip11 {
|
| 34 |
+
model: &mut TypedModel,
|
| 35 |
+
inputs: &[OutletId],
|
| 36 |
+
) -> TractResult<TVec<OutletId>> {
|
| 37 |
+
+ let dt = model.outlet_fact(inputs[0])?.datum_type;
|
| 38 |
+
let mut wire = inputs[0];
|
| 39 |
+
if let Some(min) = self.input_min {
|
| 40 |
+
+ let mut b = inputs[min];
|
| 41 |
+
+ if model.outlet_fact(b)?.datum_type != dt {
|
| 42 |
+
+ b = model.wire_node(format!("{name}.min.cast"), tract_core::ops::cast::cast(dt), &[b])?[0];
|
| 43 |
+
+ }
|
| 44 |
+
wire = wire_with_rank_broadcast(
|
| 45 |
+
format!("{name}.min"),
|
| 46 |
+
model,
|
| 47 |
+
tract_hir::ops::math::max(),
|
| 48 |
+
- &[wire, inputs[min]],
|
| 49 |
+
+ &[wire, b],
|
| 50 |
+
)?[0];
|
| 51 |
+
}
|
| 52 |
+
if let Some(max) = self.input_max {
|
| 53 |
+
+ let mut b = inputs[max];
|
| 54 |
+
+ if model.outlet_fact(b)?.datum_type != dt {
|
| 55 |
+
+ b = model.wire_node(format!("{name}.max.cast"), tract_core::ops::cast::cast(dt), &[b])?[0];
|
| 56 |
+
+ }
|
| 57 |
+
wire = wire_with_rank_broadcast(
|
| 58 |
+
format!("{name}.max"),
|
| 59 |
+
model,
|
| 60 |
+
tract_hir::ops::math::min(),
|
| 61 |
+
- &[wire, inputs[max]],
|
| 62 |
+
+ &[wire, b],
|
| 63 |
+
)?[0];
|
| 64 |
+
}
|
| 65 |
+
Ok(tvec!(wire))
|