Spaces:
Runtime error
Runtime error
Update ag4masses/alphageometry/decoder_stack.py
Browse files12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455# Copyright 2023 DeepMind Technologies Limited## Licensed 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.# =============================================================================="""The decoder stack in inference mode."""from typing import Any, Tupleimport ginfrom meliad_lib.meliad.transformer import decoder_stackimport transformer_layer as tlstruct = decoder_stack.structnn_components = decoder_stack.nn_componentsposition = decoder_stack.positionjnp = decoder_stack.jnpattention = decoder_stack.attentionDStackWindowState = decoder_stack.DStackWindowStateArray = AnyTransformerTaskConfig = decoder_stack.TransformerTaskConfigDStackDecoderState = Tuple[tl.DecoderState, ...]@gin.configurableclass DecoderStackGenerate(decoder_stack.DecoderStack):"""Stack of transformer decoder layers."""layer_factory = tl.TransformerLayerGeneratedef init_decoder_state_vanilla(self, sequence_length: int, start_of_sequence: Array) -> DStackDecoderState:"""Return initial state for autoregressive generation."""return tuple([layer.init_decoder_state_vanilla(sequence_length, start_of_sequence)for layer in self.transformer_layers])12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455# Copyright 2023 DeepMind Technologies Limited## Licensed 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.# =============================================================================="""The decoder stack in inference mode."""from typing import Any, Tupleimport ginfrom aglib.meliad.transformer import decoder_stackimport transformer_layer as tlstruct = decoder_stack.structnn_components = decoder_stack.nn_componentsposition = decoder_stack.positionjnp = decoder_stack.jnpattention = decoder_stack.attentionDStackWindowState = decoder_stack.DStackWindowStateArray = AnyTransformerTaskConfig = decoder_stack.TransformerTaskConfigDStackDecoderState = Tuple[tl.DecoderState, ...]@gin.configurableclass DecoderStackGenerate(decoder_stack.DecoderStack):"""Stack of transformer decoder layers."""layer_factory = tl.TransformerLayerGeneratedef init_decoder_state_vanilla(self, sequence_length: int, start_of_sequence: Array) -> DStackDecoderState:"""Return initial state for autoregressive generation."""return tuple([layer.init_decoder_state_vanilla(sequence_length, start_of_sequence)for layer in self.transformer_layers])
ag4masses/alphageometry/decoder_stack.py+55-55