MCPcopy Create free account
hub / github.com/THUDM/LongWriter / __init__

Method __init__

train/patch/modeling_chatglm.py:645–666  ·  view source on GitHub ↗
(self, config: ChatGLMConfig, device=None, empty_init=True)

Source from the content-addressed store, hash-verified

643
644class ChatGLMModel(ChatGLMPreTrainedModel):
645 def __init__(self, config: ChatGLMConfig, device=None, empty_init=True):
646 super().__init__(config)
647 if empty_init:
648 init_method = skip_init
649 else:
650 init_method = default_init
651 init_kwargs = {}
652 if device is not None:
653 init_kwargs["device"] = device
654 self.embedding = init_method(Embedding, config, **init_kwargs)
655
656 # Rotary positional embeddings
657 self.seq_length = config.seq_length
658 rotary_dim = (
659 config.hidden_size // config.num_attention_heads if config.kv_channels is None else config.kv_channels
660 )
661
662 self.rotary_pos_emb = RotaryEmbedding(rotary_dim // 2, rope_ratio=config.rope_ratio, original_impl=config.original_rope,
663 device=device, dtype=config.torch_dtype)
664 self.encoder = init_method(GLMTransformer, config, **init_kwargs)
665 self.output_layer = init_method(nn.Linear, config.hidden_size, config.padded_vocab_size, bias=False,
666 dtype=config.torch_dtype, **init_kwargs)
667
668 def get_input_embeddings(self):
669 return self.embedding.word_embeddings

Callers

nothing calls this directly

Calls 2

RotaryEmbeddingClass · 0.85
__init__Method · 0.45

Tested by

no test coverage detected