MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / _create_model

Method _create_model

modelzoo/deepfm/train.py:138–198  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

136 return dnn_input
137
138 def _create_model(self):
139 # input features
140 with tf.variable_scope('input_layer',
141 partitioner=self._input_layer_partitioner,
142 reuse=tf.AUTO_REUSE):
143 fm_cols = {}
144 if self._adaptive_emb and not self.tf:
145 '''Adaptive Embedding Feature Part 1 of 2'''
146 adaptive_mask_tensors = {}
147 for col in CATEGORICAL_COLUMNS:
148 adaptive_mask_tensors[col] = tf.ones([args.batch_size],
149 tf.int32)
150 dnn_input = tf.feature_column.input_layer(
151 features=self._feature,
152 feature_columns=self._deep_column,
153 adaptive_mask_tensors=adaptive_mask_tensors)
154 wide_input = tf.feature_column.input_layer(
155 self._feature, self._wide_column, cols_to_output_tensors=fm_cols, adaptive_mask_tensors=adaptive_mask_tensors)
156 else:
157 dnn_input = tf.feature_column.input_layer(self._feature,
158 self._deep_column)
159 wide_input = tf.feature_column.input_layer(
160 self._feature, self._wide_column, cols_to_output_tensors=fm_cols)
161
162 fm_input = tf.stack([fm_cols[cols] for cols in self._fm_column], 1)
163
164 if self.bf16:
165 wide_input = tf.cast(wide_input, dtype=tf.bfloat16)
166 fm_input = tf.cast(fm_input, dtype=tf.bfloat16)
167 dnn_input = tf.cast(dnn_input, dtype=tf.bfloat16)
168
169 # DNN part
170 dnn_scope = tf.variable_scope('dnn')
171 with dnn_scope.keep_weights(dtype=tf.float32) if self.bf16 \
172 else dnn_scope:
173 dnn_output = self._dnn(dnn_input, self._dnn_hidden_units,
174 'dnn_layer')
175
176 # linear / fisrt order part
177 with tf.variable_scope('linear', reuse=tf.AUTO_REUSE) as linear:
178 linear_output = tf.reduce_sum(wide_input, axis=1, keepdims=True)
179
180 # FM second order part
181 with tf.variable_scope('fm', reuse=tf.AUTO_REUSE) as fm:
182 sum_square = tf.square(tf.reduce_sum(fm_input, axis=1))
183 square_sum = tf.reduce_sum(tf.square(fm_input), axis=1)
184 fm_output = 0.5 * tf.subtract(sum_square, square_sum)
185
186 # Final dnn layer
187 all_input = tf.concat([dnn_output, linear_output, fm_output], 1)
188 final_dnn_scope = tf.variable_scope('final_dnn')
189 with final_dnn_scope.keep_weights(dtype=tf.float32) if self.bf16 \
190 else final_dnn_scope:
191 dnn_logits = self._dnn(all_input, self._final_hidden_units, 'final_dnn')
192
193 if self.bf16:
194 dnn_logits = tf.cast(dnn_logits, dtype=tf.float32)
195

Callers 1

__init__Method · 0.95

Calls 9

_dnnMethod · 0.95
variable_scopeMethod · 0.80
onesMethod · 0.80
keep_weightsMethod · 0.80
reduce_sumMethod · 0.80
stackMethod · 0.45
castMethod · 0.45
squareMethod · 0.45
concatMethod · 0.45

Tested by

no test coverage detected