You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by GitBox <gi...@apache.org> on 2019/02/17 02:04:33 UTC

[GitHub] ZhennanQin commented on a change in pull request #14173: [WIP] MXNet AMP (automatic mixed precision)

ZhennanQin commented on a change in pull request #14173: [WIP] MXNet AMP (automatic mixed precision)
URL: https://github.com/apache/incubator-mxnet/pull/14173#discussion_r257484794
 
 

 ##########
 File path: python/mxnet/amp/amp.py
 ##########
 @@ -0,0 +1,248 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+# coding: utf-8
+"""Functions for enabling AMP (automatic mixed precision)."""
+__all__ = ['init']
+
+import logging
+import contextlib
+import numpy as np
+from types import MethodType
+from functools import partial
+
+from .. import symbol
+from ..symbol import Symbol
+from .. import ndarray
+from ..ndarray import NDArray
+from . import lists
+from ..gluon import trainer
+from .. import optimizer as opt
+from .loss_scaler import *
+
+def _cast_symbol_NDArray(s, dtype):
+    if isinstance(s, Symbol):
+        return symbol.amp_cast(s, dtype=dtype)
+    elif isinstance(s, NDArray):
+        if s.dtype != dtype and (s.dtype == np.float16 or s.dtype == np.float32):
 
 Review comment:
   Is this check not enough for avoid inserting cast with same dtype? That is, why we need to add identity to cast op?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services