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.

loss_info.h 2.5 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. #ifndef MINDSPORE_CCSRC_PARALLEL_OPS_INFO_LOSS_INFO_H_
  17. #define MINDSPORE_CCSRC_PARALLEL_OPS_INFO_LOSS_INFO_H_
  18. #include <memory>
  19. #include <string>
  20. #include <unordered_map>
  21. #include <vector>
  22. #include "ir/value.h"
  23. #include "parallel/ops_info/activation_info.h"
  24. #include "parallel/ops_info/operator_info.h"
  25. #include "parallel/strategy.h"
  26. namespace mindspore {
  27. namespace parallel {
  28. // infer shape:
  29. // input_0 : [a, b], input_1 : [a, b]
  30. // output_0 : [a], output_1: [a, b]
  31. class SoftmaxCrossEntropyWithLogitsInfo : public OperatorInfo {
  32. public:
  33. SoftmaxCrossEntropyWithLogitsInfo(const std::string &name, const Shapes &inputs_shape, const Shapes &outputs_shape,
  34. const PrimitiveAttrs &attrs)
  35. : OperatorInfo(name, inputs_shape, outputs_shape, attrs,
  36. std::make_shared<SoftmaxCrossEntropyWithLogitsCost>(false)) {}
  37. ~SoftmaxCrossEntropyWithLogitsInfo() override = default;
  38. Status Init(const StrategyPtr &strategy) override;
  39. Status InitForCostModel(const StrategyPtr &strategy) override;
  40. Status GenerateStrategies(int32_t stage_id) override;
  41. Status SetCostUnderStrategy(const StrategyPtr &strategy) override;
  42. void ReComputeBatchSplitFlagList() override;
  43. protected:
  44. Status CheckStrategy(const StrategyPtr &strategy) override;
  45. Status GetAttrs() override;
  46. Status InferMirrorOps() override { return SUCCESS; }
  47. Status InferForwardCommunication() override { return SUCCESS; }
  48. Status InferTensorMap() override;
  49. Status InferTensorInfo() override;
  50. Status InferDevMatrixShape() override;
  51. // There are two outputs for SoftmaxCrossEntropyWithLogits, and outputs[1] is used for grad and overload
  52. // the InferAsLossDivisor.
  53. Status InferAsLossDivisor() override;
  54. private:
  55. int32_t axis_ = -1; // default -1
  56. };
  57. } // namespace parallel
  58. } // namespace mindspore
  59. #endif // MINDSPORE_CCSRC_PARALLEL_OPS_INFO_LOSS_INFO_H_