| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent bf91102 commit d4f3df2
11 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -82,33 +82,40 @@ public OwnedIterator make_one_shot_iterator() | |||
| 82 | 82 | public IDatasetV2 flat_map(Func<Tensor, IDatasetV2> map_func) | |
| 83 | 83 | => new FlatMapDataset(this, map_func); | |
| 84 | 84 | ||
| 85 | - public IDatasetV2 model(AutotuneAlgorithm algorithm, long cpu_budget) | ||
| 86 | - => new ModelDataset(this, algorithm, cpu_budget); | ||
| 85 | + public IDatasetV2 model(AutotuneAlgorithm algorithm, long cpu_budget, long ram_budget) | ||
| 86 | + => new ModelDataset(this, algorithm, cpu_budget, ram_budget); | ||
| 87 | 87 | ||
| 88 | 88 | public IDatasetV2 with_options(DatasetOptions options) | |
| 89 | 89 | => new OptionsDataset(this, options); | |
| 90 | 90 | ||
| 91 | 91 | public IDatasetV2 apply_options() | |
| 92 | 92 | { | |
| 93 | + IDatasetV2 dataset = this; | ||
| 93 | 94 | // (1) Apply threading options | |
| 95 | + | ||
| 96 | + // (2) Apply autotune options | ||
| 97 | + var autotune = true; | ||
| 98 | + long cpu_budget = 0; | ||
| 99 | + long ram_budget = 0; | ||
| 100 | + if (autotune) | ||
| 101 | + dataset = dataset.model(AutotuneAlgorithm.HILL_CLIMB, cpu_budget, ram_budget); | ||
| 102 | + | ||
| 103 | + // (3) Apply graph rewrite options | ||
| 94 | 104 | var graph_rewrites = new[] | |
| 95 | 105 | { | |
| 96 | - "map_and_batch_fusion", | ||
| 97 | 106 | "noop_elimination", | |
| 107 | + "map_and_batch_fusion", | ||
| 98 | 108 | "shuffle_and_repeat_fusion" | |
| 99 | 109 | }; | |
| 110 | + var graph_rewrite_configs = new string[] | ||
| 111 | + { | ||
| 112 | + "autotune_buffer_sizes:autotune:true", | ||
| 113 | + "disable_prefetch_legacy_autotune:autotune:true", | ||
| 114 | + "enable_gradient_descent:autotune:true", | ||
| 115 | + "map_parallelization:autotune:true" | ||
| 116 | + }; | ||
| 100 | 117 | ||
| 101 | - var graph_rewrite_configs = new string[0]; | ||
| 102 | - | ||
| 103 | - // (2) Apply graph rewrite options | ||
| 104 | - var dataset = optimize(graph_rewrites, graph_rewrite_configs); | ||
| 105 | - | ||
| 106 | - // (3) Apply autotune options | ||
| 107 | - var autotune = true; | ||
| 108 | - long cpu_budget = 0; | ||
| 109 | - | ||
| 110 | - if (autotune) | ||
| 111 | - dataset = dataset.model(AutotuneAlgorithm.HILL_CLIMB, cpu_budget); | ||
| 118 | + dataset = new OptimizeDataset(dataset, new string[0], new string[0], graph_rewrites, graph_rewrite_configs); | ||
| 112 | 119 | ||
| 113 | 120 | // (4) Apply stats aggregator options | |
| 114 | 121 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -76,7 +76,7 @@ IDatasetV2 map(Func<Tensors, Tensors> map_func, | |||
| 76 | 76 | ||
| 77 | 77 | IDatasetV2 flat_map(Func<Tensor, IDatasetV2> map_func); | |
| 78 | 78 | ||
| 79 | - IDatasetV2 model(AutotuneAlgorithm algorithm, long cpu_budget); | ||
| 79 | + IDatasetV2 model(AutotuneAlgorithm algorithm, long cpu_budget, long ram_budget); | ||
| 80 | 80 | ||
| 81 | 81 | IDatasetV2 with_options(DatasetOptions options); | |
| 82 | 82 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -9,14 +9,16 @@ public class ModelDataset : UnaryUnchangedStructureDataset | |||
| 9 | 9 | { | |
| 10 | 10 | public ModelDataset(IDatasetV2 input_dataset, | |
| 11 | 11 | AutotuneAlgorithm algorithm, | |
| 12 | - long cpu_budget) : | ||
| 12 | + long cpu_budget, | ||
| 13 | + long ram_budget) : | ||
| 13 | 14 | base(input_dataset) | |
| 14 | 15 | { | |
| 15 | 16 | variant_tensor = ops.model_dataset(input_dataset.variant_tensor, | |
| 16 | 17 | output_types, | |
| 17 | 18 | output_shapes, | |
| 18 | 19 | algorithm, | |
| 19 | - cpu_budget); | ||
| 20 | + cpu_budget, | ||
| 21 | + ram_budget); | ||
| 20 | 22 | } | |
| 21 | 23 | } | |
| 22 | 24 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -8,19 +8,30 @@ namespace Tensorflow | |||
| 8 | 8 | public class OptimizeDataset : UnaryUnchangedStructureDataset | |
| 9 | 9 | { | |
| 10 | 10 | public OptimizeDataset(IDatasetV2 dataset, | |
| 11 | - string[] optimizations = null, | ||
| 11 | + string[] optimizations_enabled = null, | ||
| 12 | + string[] optimizations_disabled = null, | ||
| 13 | + string[] optimizations_default = null, | ||
| 12 | 14 | string[] optimization_configs = null) : | |
| 13 | 15 | base(dataset) | |
| 14 | 16 | { | |
| 15 | - if (optimizations == null) | ||
| 16 | - optimizations = new string[0]; | ||
| 17 | + if (optimizations_enabled == null) | ||
| 18 | + optimizations_enabled = new string[0]; | ||
| 19 | + if (optimizations_disabled == null) | ||
| 20 | + optimizations_disabled = new string[0]; | ||
| 21 | + if (optimizations_default == null) | ||
| 22 | + optimizations_default = new string[0]; | ||
| 17 | 23 | if (optimization_configs == null) | |
| 18 | 24 | optimization_configs = new string[0]; | |
| 19 | 25 | ||
| 20 | - var _optimizations = tf.convert_to_tensor(optimizations, dtype: TF_DataType.TF_STRING, name: "optimizations"); | ||
| 21 | - variant_tensor = ops.optimize_dataset( | ||
| 26 | + var _optimizations_enabled = tf.convert_to_tensor(optimizations_enabled, dtype: TF_DataType.TF_STRING, name: "optimizations_enabled"); | ||
| 27 | + var _optimizations_disabled = tf.convert_to_tensor(optimizations_disabled, dtype: TF_DataType.TF_STRING, name: "optimizations_disabled"); | ||
| 28 | + var _optimizations_default = tf.convert_to_tensor(optimizations_default, dtype: TF_DataType.TF_STRING, name: "optimizations_default"); | ||
| 29 | + | ||
| 30 | + variant_tensor = ops.optimize_dataset_v2( | ||
| 22 | 31 | _input_dataset.variant_tensor, | |
| 23 | - _optimizations, | ||
| 32 | + _optimizations_enabled, | ||
| 33 | + _optimizations_disabled, | ||
| 34 | + _optimizations_default, | ||
| 24 | 35 | output_types, | |
| 25 | 36 | output_shapes, | |
| 26 | 37 | optimization_configs: optimization_configs); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -295,7 +295,7 @@ bool SetOpAttrList(Context ctx, SafeOpHandle op, | |||
| 295 | 295 | { | |
| 296 | 296 | if (type == TF_AttrType.TF_ATTR_STRING && values is string[] values3) | |
| 297 | 297 | { | |
| 298 | - c_api.TFE_OpSetAttrStringList(op, key, new IntPtr[0], values3.Select(x => x.Length).ToArray(), values3.Length); | ||
| 298 | + c_api.TFE_OpSetAttrStringList(op, key, values3, values3.Select(x => Convert.ToUInt64(x.Length)).ToArray(), values3.Length); | ||
| 299 | 299 | attr_list_sizes[key] = values3.Length; | |
| 300 | 300 | } | |
| 301 | 301 | else if (type == TF_AttrType.TF_ATTR_SHAPE && values is TensorShape[] values1) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -252,7 +252,7 @@ public static void TFE_Execute(SafeOpHandle op, SafeTensorHandleHandle[] retvals | |||
| 252 | 252 | public static extern void TFE_OpSetAttrShapeList(SafeOpHandle op, string attr_name, IntPtr[] dims, int[] num_dims, int num_values, SafeStatusHandle out_status); | |
| 253 | 253 | ||
| 254 | 254 | [DllImport(TensorFlowLibName)] | |
| 255 | - public static extern void TFE_OpSetAttrStringList(SafeOpHandle op, string attr_name, IntPtr[] values, int[] lengths, int num_values); | ||
| 255 | + public static extern void TFE_OpSetAttrStringList(SafeOpHandle op, string attr_name, string[] values, ulong[] lengths, int num_values); | ||
| 256 | 256 | ||
| 257 | 257 | [DllImport(TensorFlowLibName)] | |
| 258 | 258 | public static extern void TFE_OpSetAttrBool(SafeOpHandle op, string attr_name, bool value); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -67,8 +67,19 @@ public static (Tensor, Tensor) get_seed_tensor(int? op_seed = null) | |||
| 67 | 67 | if (seed2 is null) | |
| 68 | 68 | _seed2 = constant_op.constant(0, dtype: TF_DataType.TF_INT64, name: "seed2"); | |
| 69 | 69 | else | |
| 70 | - _seed2 = constant_op.constant(seed2.Value, dtype: TF_DataType.TF_INT64, name: "seed2"); | ||
| 71 | - | ||
| 70 | + { | ||
| 71 | + _seed2 = tf_with(ops.name_scope("seed2"), scope => | ||
| 72 | + { | ||
| 73 | + _seed2 = constant_op.constant(seed2.Value, dtype: TF_DataType.TF_INT64); | ||
| 74 | + return array_ops.where_v2( | ||
| 75 | + math_ops.logical_and( | ||
| 76 | + math_ops.equal(_seed, 0l), math_ops.equal(_seed2, 0l)), | ||
| 77 | + constant_op.constant(2^31 - 1, dtype: dtypes.int64), | ||
| 78 | + _seed2, | ||
| 79 | + name: scope); | ||
| 80 | + }); | ||
| 81 | + } | ||
| 82 | + | ||
| 72 | 83 | return (_seed, _seed2); | |
| 73 | 84 | } | |
| 74 | 85 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -168,6 +168,20 @@ public Tensor optimize_dataset(Tensor input_dataset, Tensor optimizations, | |||
| 168 | 168 | optimization_configs = optimization_configs ?? new string[0] | |
| 169 | 169 | })); | |
| 170 | 170 | ||
| 171 | + public Tensor optimize_dataset_v2(Tensor input_dataset, Tensor optimizations_enabled, | ||
| 172 | + Tensor optimizations_disabled, Tensor optimizations_default, | ||
| 173 | + TF_DataType[] output_types, TensorShape[] output_shapes, | ||
| 174 | + string[] optimization_configs = null, | ||
| 175 | + string name = null) | ||
| 176 | + => tf.Context.ExecuteOp("OptimizeDatasetV2", name, new ExecuteOpArgs(input_dataset, | ||
| 177 | + optimizations_enabled, optimizations_disabled, optimizations_default) | ||
| 178 | + .SetAttributes(new | ||
| 179 | + { | ||
| 180 | + output_types, | ||
| 181 | + output_shapes, | ||
| 182 | + optimization_configs = optimization_configs ?? new string[0] | ||
| 183 | + })); | ||
| 184 | + | ||
| 171 | 185 | /// <summary> | |
| 172 | 186 | /// Identity transformation that models performance. | |
| 173 | 187 | /// </summary> | |
@@ -180,13 +194,14 @@ public Tensor optimize_dataset(Tensor input_dataset, Tensor optimizations, | |||
| 180 | 194 | /// <returns></returns> | |
| 181 | 195 | public Tensor model_dataset(Tensor input_dataset, | |
| 182 | 196 | TF_DataType[] output_types, TensorShape[] output_shapes, | |
| 183 | - AutotuneAlgorithm algorithm, long cpu_budget, | ||
| 197 | + AutotuneAlgorithm algorithm, long cpu_budget, long ram_budget, | ||
| 184 | 198 | string name = null) | |
| 185 | 199 | => tf.Context.ExecuteOp("ModelDataset", name, new ExecuteOpArgs(input_dataset) | |
| 186 | 200 | .SetAttributes(new | |
| 187 | 201 | { | |
| 188 | 202 | algorithm, | |
| 189 | 203 | cpu_budget, | |
| 204 | + ram_budget, | ||
| 190 | 205 | output_types, | |
| 191 | 206 | output_shapes | |
| 192 | 207 | })); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -327,24 +327,16 @@ public static Tensor log1p(Tensor x, string name = null) | |||
| 327 | 327 | => tf.Context.ExecuteOp("Log1p", name, new ExecuteOpArgs(x)); | |
| 328 | 328 | ||
| 329 | 329 | public static Tensor logical_and(Tensor x, Tensor y, string name = null) | |
| 330 | - => tf.OpDefLib._apply_op_helper("LogicalAnd", name, args: new { x, y }); | ||
| 330 | + => tf.Context.ExecuteOp("LogicalAnd", name, new ExecuteOpArgs(x, y)); | ||
| 331 | 331 | ||
| 332 | 332 | public static Tensor logical_and(bool x, bool y, string name = null) | |
| 333 | 333 | => tf.Context.ExecuteOp("LogicalAnd", name, new ExecuteOpArgs(x, y)); | |
| 334 | 334 | ||
| 335 | 335 | public static Tensor logical_not(Tensor x, string name = null) | |
| 336 | - { | ||
| 337 | - var _op = tf.OpDefLib._apply_op_helper("LogicalNot", name, args: new { x }); | ||
| 338 | - | ||
| 339 | - return _op.outputs[0]; | ||
| 340 | - } | ||
| 336 | + => tf.Context.ExecuteOp("LogicalNot", name, new ExecuteOpArgs(x)); | ||
| 341 | 337 | ||
| 342 | 338 | public static Tensor logical_or(Tensor x, Tensor y, string name = null) | |
| 343 | - { | ||
| 344 | - var _op = tf.OpDefLib._apply_op_helper("LogicalOr", name, args: new { x, y }); | ||
| 345 | - | ||
| 346 | - return _op.outputs[0]; | ||
| 347 | - } | ||
| 339 | + => tf.Context.ExecuteOp("LogicalOr", name, new ExecuteOpArgs(x, y)); | ||
| 348 | 340 | ||
| 349 | 341 | public static Tensor logical_xor(Tensor x, Tensor y, string name = "LogicalXor") | |
| 350 | 342 | { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -77,10 +77,10 @@ public static Tensor random_uniform(Tensor shape, TF_DataType dtype, int? seed = | |||
| 77 | 77 | /// <param name="seed2"></param> | |
| 78 | 78 | /// <param name="name"></param> | |
| 79 | 79 | /// <returns></returns> | |
| 80 | - public static Tensor random_shuffle(Tensor value, int seed = 0, int seed2 = 0, | ||
| 80 | + public static Tensor random_shuffle(Tensor value, int? seed = 0, int? seed2 = 0, | ||
| 81 | 81 | string name = null) | |
| 82 | 82 | => tf.Context.ExecuteOp("RandomShuffle", name, new ExecuteOpArgs(value) | |
| 83 | - .SetAttributes(new { seed = seed, seed2 = seed2 })); | ||
| 83 | + .SetAttributes(new { seed = seed ?? 0, seed2 = seed2 ?? 0 })); | ||
| 84 | 84 | ||
| 85 | 85 | /// <summary> | |
| 86 | 86 | /// Outputs random values from a truncated normal distribution. | |
| Back | FazBrowse Home | New Git URL |
0 commit comments