Added MHA and related nodes.

This commit is contained in:
HowToSD
2025-04-06 18:18:44 -07:00
parent a2490be96f
commit ca1644d2f5
29 changed files with 1219 additions and 11 deletions
+9
View File
@@ -8,6 +8,10 @@
| Node | Description |
| --- | --- |
| [Pt Save Model](pt_save_model.md) | A wrapper class for saving a PyTorch model. |
## Miscellaneous
| Node | Description |
| --- | --- |
| [Ptn Model With Closure](ptn_model_with_closure.md) | A model that is followed by a closure function. |
## PyTorch wrapper - Arithmetic operations
| Node | Description |
| --- | --- |
@@ -154,6 +158,7 @@
| [Ptn Avg Pool 2d](ptn_avg_pool2d.md) | An avgpool layer. |
| [Ptn Batch Norm 2d](ptn_batch_norm2d.md) | A normalization model to normalize over the batch and spatial axes for each channel. |
| [Ptn Chained Model](ptn_chained_model.md) | Constructs a chained PyTorch model. |
| [Ptn Chained Model With Attention Mask](ptn_chained_model_with_attention_mask.md) | A chained model that sequentially applies `model_a` and `model_b`, |
| [Ptn Conv 2d](ptn_conv2d.md) | A convolutional model consisting of a single conv2d layer. |
| [Ptn Conv Model](ptn_conv_model.md) | A convolutional model consisting of multiple convolutional layers. |
| [Ptn Embedding](ptn_embedding.md) | Constructs an embedding layer. |
@@ -168,12 +173,16 @@
| [Ptn Layer Norm](ptn_layer_norm.md) | A normalization model to normalize elements over specified axes. |
| [Ptn Linear](ptn_linear.md) | A linear model consisting of a single dense layer. |
| [Ptn Linear Model](ptn_linear_model.md) | A linear model consisting of dense layers. |
| [Ptn Masked Mean Pooling](ptn_masked_mean_pooling.md) | Constructs a masked mean pooling layer. |
| [Ptn Max Pool 2d](ptn_max_pool2d.md) | A maxpool layer. |
| [Ptn Multihead Attention](ptn_multihead_attention.md) | A Multihead attention model. |
| [Ptn Pre Add Channel Axis](ptn_pre_add_channel_axis.md) | Adds a channel axis after the batch axis if the input is rank 3 (bs, h, w) |
| [Ptn Pre Flatten](ptn_pre_flatten.md) | Flattens the input tensor before processing the tensor in the specified model. |
| [Ptn RNN](ptn_rnn.md) | A recurrent neural network (RNN) model consisting of one or more of a recurrent layer. |
| [Ptn RNN Linear](ptn_embedding_rnn_linear.md) | A recurrent neural network (RNN) model with a linear head. |
| [Ptn RNN Linear](ptn_rnn_linear.md) | A recurrent neural network (RNN) model with a linear head. |
| [Ptn Residual Connection Model](ptn_residual_connection_model.md) | A model that saves the input and add to the output of the specified model. |
| [Ptn Residual Connection Model With Attention Mask](ptn_residual_connection_model_with_attention_mask.md) | A model that saves the input and add to the output of the specified model. |
| [Ptn Resnet Model](ptn_resnet_model.md) | A Resnet model consisting of multiple Resnet layers. |
## PyTorch wrapper - Optimizer
| Node | Description |
@@ -13,7 +13,9 @@ Trains a classification Transformer model using a given dataset, loss function,
output_best_val_model (bool): Whether to outputs the model with the best val loss or the model from the last epoch.
classification_metrics (bool): If True and if val_loader is set, print out classification metrics. This is only valid for classification model training.
val_loader (PTDATALOADER): DataLoader for validation dataset (optional).
scheduler (PTLRSCHEDULER): Learning rate scheduler.
scheduler (PTLRSCHEDULER): Learning rate scheduler.
unpack_input (Optional[bool]): If True and the input is a list, unpack it when calling the model.
For example, if the dataloader returns [a, b] and your model's forward is defined as forward(a, b), set this to True.
## Input
| Name | Data type |
@@ -30,6 +32,7 @@ Trains a classification Transformer model using a given dataset, loss function,
| classification_metrics | Boolean |
| scheduler | Ptlrscheduler |
| val_loader | Ptdataloader |
| unpack_input | Boolean |
## Output
| Data type |
@@ -0,0 +1,29 @@
# Ptn Chained Model With Attention Mask
A chained model that sequentially applies `model_a` and `model_b`,
optionally followed by a closure function.
### Fields:
- `model_a`: First model in the chain.
- `model_b`: Second model in the chain.
- `model_a_mask_req`: True if model_a requires attention_mask for input
- `model_b_mask_req`: True if model_b requires attention_mask for input
- closure: Optional differentiable function to be called at the end of forward.
## Input
| Name | Data type |
|---|---|
| model_a | Ptmodel |
| model_b | Ptmodel |
| model_a_mask_req | Boolean |
| model_b_mask_req | Boolean |
| closure | Ptcallable |
## Output
| Data type |
|---|
| Ptmodel |
<HR>
Category: PyTorch wrapper - Model
ComfyUI Pt Wrapper Node Reference. © 2025 Hide Inada (HowToSD.com). All rights reserved.
+1 -1
View File
@@ -10,7 +10,7 @@ Constructs an embedding layer.
| Name | Data type |
|---|---|
| num_embeddings | Int |
| embedding_size | Int |
| embedding_dim | Int |
| padding_idx | Int |
## Output
+13
View File
@@ -0,0 +1,13 @@
# Ptn Masked Mean Pooling
Constructs a masked mean pooling layer.
Computes the mean of the input excluding the padding values using the given mask.
## Output
| Data type |
|---|
| Ptmodel |
<HR>
Category: PyTorch wrapper - Model
ComfyUI Pt Wrapper Node Reference. © 2025 Hide Inada (HowToSD.com). All rights reserved.
+22
View File
@@ -0,0 +1,22 @@
# Ptn Model With Closure
A model that is followed by a closure function.
### Fields:
- `model`: The model in the chain.
- `closure`: Differentiable function to be called at the end of forward. category: PyTorch wrapper - Model
## Input
| Name | Data type |
|---|---|
| model | Ptmodel |
| closure | Ptcallable |
## Output
| Data type |
|---|
| Ptmodel |
<HR>
Category: Miscellaneous
ComfyUI Pt Wrapper Node Reference. © 2025 Hide Inada (HowToSD.com). All rights reserved.
+36
View File
@@ -0,0 +1,36 @@
# Ptn Multihead Attention
A Multihead attention model.
Args:
embed_dim (int): Hidden dimension (d_model) for each token of the Transformer.
num_heads (int): Number of attention heads.
dropout (float): Dropout rate for output.
bias (bool): If True, bias will be added to the linear projections of query, key, value, and the final output.
add_bias_kv (bool): If True, bias will be added to k and v sequences.
add_zero_attn (bool): If True, a zero batch will be added to k and v sequences.
kdim (int): Dimension of k.
vdim (int): Dimension of v.
batch_first (bool): Input shape format: True for (B, Seq, Feature), False for (Seq, B, Feature).
## Input
| Name | Data type |
|---|---|
| embed_dim | Int |
| num_heads | Int |
| dropout | Float |
| bias | Boolean |
| add_bias_kv | Boolean |
| add_zero_attn | Boolean |
| kdim | Int |
| vdim | Int |
| batch_first | Boolean |
## Output
| Data type |
|---|
| Ptmodel |
<HR>
Category: PyTorch wrapper - Model
ComfyUI Pt Wrapper Node Reference. © 2025 Hide Inada (HowToSD.com). All rights reserved.
@@ -0,0 +1,23 @@
# Ptn Residual Connection Model
A model that saves the input and add to the output of the specified model.
optionally followed by a closure function.
### Fields:
- `model`: A model to process input.
- `closure`: Optional differentiable function to be called at the end of forward.
## Input
| Name | Data type |
|---|---|
| model | Ptmodel |
| closure | Ptcallable |
## Output
| Data type |
|---|
| Ptmodel |
<HR>
Category: PyTorch wrapper - Model
ComfyUI Pt Wrapper Node Reference. © 2025 Hide Inada (HowToSD.com). All rights reserved.
@@ -0,0 +1,23 @@
# Ptn Residual Connection Model With Attention Mask
A model that saves the input and add to the output of the specified model.
optionally followed by a closure function.
### Fields:
- `model`: A model to process input.
- `closure`: Optional differentiable function to be called at the end of forward.
## Input
| Name | Data type |
|---|---|
| model | Ptmodel |
| closure | Ptcallable |
## Output
| Data type |
|---|
| Ptmodel |
<HR>
Category: PyTorch wrapper - Model
ComfyUI Pt Wrapper Node Reference. © 2025 Hide Inada (HowToSD.com). All rights reserved.
+2 -1
View File
@@ -5,7 +5,8 @@ A PyTorch Dataset class wrapper for a Hugging Face dataset to load a dataset tha
file_path (str): Path to the dataset file. Can be an absolute path or a relative path.
If a relative path is provided, it is resolved from the `datasets` directory under this extension.
For example, to load `datasets/foo/bar_train.jsonp`, specify `foo/bar_train.jsonp` or the absolute path.
file_format (str): File format (e.g. json if the file is in jsonl format). sample_field_name (str): Field name for text samples.
file_format (str): File format (e.g. json if the file is in jsonl format).
sample_field_name (str): Field name for text samples.
label_field_name (str): Field name for labels.
encode (PTCALLABLE): The reference to a token encoder function.
remove_html_tags (bool): Remove html tags in text if True.