You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

prim_debug.cc 3.2 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /**
  2. * Copyright 2019 Huawei Technologies Co., Ltd
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #include "pipeline/static_analysis/param_validator.h"
  17. #include "pipeline/static_analysis/prim.h"
  18. #include "operator/ops.h"
  19. #include "pipeline/static_analysis/utils.h"
  20. #include "utils/symbolic.h"
  21. namespace mindspore {
  22. namespace abstract {
  23. AbstractBasePtr InferImplScalarSummary(const AnalysisEnginePtr &, const PrimitivePtr &primitive,
  24. const AbstractBasePtrList &args_spec_list) {
  25. // Inputs: a scalar and a tensor or scalar.
  26. const std::string op_name = primitive->name();
  27. CheckArgsSize(op_name, args_spec_list, 2);
  28. // check the tag
  29. AbstractScalarPtr descriptions = CheckArg<AbstractScalar>(op_name, args_spec_list, 0);
  30. // check the value: scalar or shape = (1,)
  31. auto scalar_value = dyn_cast<AbstractScalar>(args_spec_list[1]);
  32. if (scalar_value == nullptr) {
  33. auto tensor_value = dyn_cast<AbstractTensor>(args_spec_list[1]);
  34. if (tensor_value == nullptr) {
  35. MS_LOG(EXCEPTION) << "Input must be scalar or shape(1,)";
  36. }
  37. } else {
  38. auto item_v = scalar_value->BuildValue();
  39. if (item_v->isa<StringImm>()) {
  40. auto value = item_v->cast<StringImmPtr>()->value();
  41. if (value.empty()) {
  42. MS_LOG(EXCEPTION) << "Input summary value can't be null";
  43. }
  44. }
  45. }
  46. // Reomve the force check to support batch set summary use 'for' loop
  47. auto item_v = descriptions->BuildValue();
  48. if (!item_v->isa<StringImm>()) {
  49. MS_EXCEPTION(TypeError) << "Summary first parameter should be string";
  50. }
  51. return std::make_shared<AbstractScalar>(kAnyValue, kBool);
  52. }
  53. AbstractBasePtr InferImplTensorSummary(const AnalysisEnginePtr &, const PrimitivePtr &primitive,
  54. const AbstractBasePtrList &args_spec_list) {
  55. // Inputs: a scalar(tag) and a tensor(value)
  56. const std::string op_name = primitive->name();
  57. CheckArgsSize(op_name, args_spec_list, 2);
  58. // check the tag
  59. auto descriptions = CheckArg<AbstractScalar>(op_name, args_spec_list, 0);
  60. auto tensor_value = CheckArg<AbstractTensor>(op_name, args_spec_list, 1);
  61. int tensor_rank = SizeToInt(tensor_value->shape()->shape().size());
  62. if (tensor_rank == 0) {
  63. MS_LOG(EXCEPTION) << op_name << " summary evaluator second arg should be an tensor, but got a scalar, rank is 0";
  64. }
  65. // Reomve the force check to support batch set summary use 'for' loop
  66. auto item_v = descriptions->BuildValue();
  67. if (!item_v->isa<StringImm>()) {
  68. MS_EXCEPTION(TypeError) << "Summary first parameter should be string";
  69. }
  70. return std::make_shared<AbstractScalar>(kAnyValue, std::make_shared<Bool>());
  71. }
  72. } // namespace abstract
  73. } // namespace mindspore