add tensor dim guard for layers