license import '@tensorflow/tfjs-backend-cpu' ; import '@tensorflow/tfjs-backend-webgl' ; import * as tfc from '@tensorflow/tfjs-core' ; import '@tensorflow/tfjs-core/dist/register_all_gradients' ; import { ALL_ENVS , describeWithFlags } from '@tensorflow/tfjs-core/dist/jasmine_util' ; import * as tfl from '@tensorflow/tfjs-layers' ; import { SMOKE } from './constants' ; /**
 *  Tests that tf.grad works for layers models.
 *  Regression test for https://github.com/tensorflow/tfjs/issues/4130
 */ describe ( `${ SMOKE } tf.grad for layers models` , ( ) => { describeWithFlags ( `layers_model` , ALL_ENVS , ( ) => { let model ; beforeAll ( async ( ) => { model = tfl . sequential ( ) ; model . add ( tfl . layers . dense ( { inputShape : [ 1 ] , units : 1 } ) ) ; } ) ; it ( `can compute grad of prediction` , async ( ) => { const forward = ( x ) => model . predict ( x ) as tfc . Tensor ; const grad = tfc . grad ( forward ) ; const input = tfc . tensor ( [ 1 ] , [ 1 , 1 ] ) ; const dy = tfc . onesLike ( input ) ; expect ( ( ) => { grad ( input , dy ) ; } ) . not . toThrow ( ) ; } ) ; } ) ; } ) ;