Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
self.projection = common_spec.LinearSpec()
self.layer = [
TransformerDecoderLayerSpec() for _ in range(num_layers)]
class TransformerEncoderLayerSpec(model_spec.LayerSpec):
def __init__(self):
self.self_attention = attention_spec.MultiHeadAttentionSpec(self_attention=True)
self.ffn = FeedForwardSpec()
class TransformerDecoderLayerSpec(model_spec.LayerSpec):
def __init__(self):
self.self_attention = attention_spec.MultiHeadAttentionSpec(self_attention=True)
self.attention = attention_spec.MultiHeadAttentionSpec()
self.ffn = FeedForwardSpec()
class FeedForwardSpec(model_spec.LayerSpec):
def __init__(self):
self.layer_norm = common_spec.LayerNormSpec()
self.linear_0 = common_spec.LinearSpec()
self.linear_1 = common_spec.LinearSpec()
class PositionEncoderSpec(model_spec.LayerSpec):
def __init__(self):
self.encodings = model_spec.OPTIONAL
def __init__(self, num_layers):
self.embeddings = common_spec.EmbeddingsSpec()
self.position_encodings = PositionEncoderSpec()
self.layer_norm = common_spec.LayerNormSpec()
self.layer = [TransformerEncoderLayerSpec() for _ in range(num_layers)]
class TransformerDecoderSpec(model_spec.LayerSpec):
def __init__(self, num_layers):
self.embeddings = common_spec.EmbeddingsSpec()
self.position_encodings = PositionEncoderSpec()
self.layer_norm = common_spec.LayerNormSpec()
self.projection = common_spec.LinearSpec()
self.layer = [
TransformerDecoderLayerSpec() for _ in range(num_layers)]
class TransformerEncoderLayerSpec(model_spec.LayerSpec):
def __init__(self):
self.self_attention = attention_spec.MultiHeadAttentionSpec(self_attention=True)
self.ffn = FeedForwardSpec()
class TransformerDecoderLayerSpec(model_spec.LayerSpec):
def __init__(self):
self.self_attention = attention_spec.MultiHeadAttentionSpec(self_attention=True)
self.attention = attention_spec.MultiHeadAttentionSpec()
self.ffn = FeedForwardSpec()
class FeedForwardSpec(model_spec.LayerSpec):
def __init__(self):
self.layer_norm = common_spec.LayerNormSpec()
self.linear_0 = common_spec.LinearSpec()
self.linear_1 = common_spec.LinearSpec()
class TransformerDecoderSpec(model_spec.LayerSpec):
def __init__(self, num_layers):
self.embeddings = common_spec.EmbeddingsSpec()
self.position_encodings = PositionEncoderSpec()
self.layer_norm = common_spec.LayerNormSpec()
self.projection = common_spec.LinearSpec()
self.layer = [
TransformerDecoderLayerSpec() for _ in range(num_layers)]
class TransformerEncoderLayerSpec(model_spec.LayerSpec):
def __init__(self):
self.self_attention = attention_spec.MultiHeadAttentionSpec(self_attention=True)
self.ffn = FeedForwardSpec()
class TransformerDecoderLayerSpec(model_spec.LayerSpec):
def __init__(self):
self.self_attention = attention_spec.MultiHeadAttentionSpec(self_attention=True)
self.attention = attention_spec.MultiHeadAttentionSpec()
self.ffn = FeedForwardSpec()
class FeedForwardSpec(model_spec.LayerSpec):
def __init__(self):
self.layer_norm = common_spec.LayerNormSpec()
self.linear_0 = common_spec.LinearSpec()
self.linear_1 = common_spec.LinearSpec()
class PositionEncoderSpec(model_spec.LayerSpec):
def __init__(self):
self.encodings = model_spec.OPTIONAL
@property
def source_vocabulary_size(self):
return self.encoder.embeddings.weight.shape[0]
@property
def target_vocabulary_size(self):
return self.decoder.embeddings.weight.shape[0]
class TransformerEncoderSpec(model_spec.LayerSpec):
def __init__(self, num_layers):
self.embeddings = common_spec.EmbeddingsSpec()
self.position_encodings = PositionEncoderSpec()
self.layer_norm = common_spec.LayerNormSpec()
self.layer = [TransformerEncoderLayerSpec() for _ in range(num_layers)]
class TransformerDecoderSpec(model_spec.LayerSpec):
def __init__(self, num_layers):
self.embeddings = common_spec.EmbeddingsSpec()
self.position_encodings = PositionEncoderSpec()
self.layer_norm = common_spec.LayerNormSpec()
self.projection = common_spec.LinearSpec()
self.layer = [
TransformerDecoderLayerSpec() for _ in range(num_layers)]
class TransformerEncoderLayerSpec(model_spec.LayerSpec):
def __init__(self):
self.self_attention = attention_spec.MultiHeadAttentionSpec(self_attention=True)
self.ffn = FeedForwardSpec()
class TransformerDecoderLayerSpec(model_spec.LayerSpec):
def __init__(self):
self.self_attention = attention_spec.MultiHeadAttentionSpec(self_attention=True)
self.encoder = TransformerEncoderSpec(num_layers)
self.decoder = TransformerDecoderSpec(num_layers)
@property
def revision(self):
return 3
@property
def source_vocabulary_size(self):
return self.encoder.embeddings.weight.shape[0]
@property
def target_vocabulary_size(self):
return self.decoder.embeddings.weight.shape[0]
class TransformerEncoderSpec(model_spec.LayerSpec):
def __init__(self, num_layers):
self.embeddings = common_spec.EmbeddingsSpec()
self.position_encodings = PositionEncoderSpec()
self.layer_norm = common_spec.LayerNormSpec()
self.layer = [TransformerEncoderLayerSpec() for _ in range(num_layers)]
class TransformerDecoderSpec(model_spec.LayerSpec):
def __init__(self, num_layers):
self.embeddings = common_spec.EmbeddingsSpec()
self.position_encodings = PositionEncoderSpec()
self.layer_norm = common_spec.LayerNormSpec()
self.projection = common_spec.LinearSpec()
self.layer = [
TransformerDecoderLayerSpec() for _ in range(num_layers)]
class TransformerEncoderLayerSpec(model_spec.LayerSpec):