# -*- coding: utf-8 -*-
from setuptools import setup

packages = \
['mmca_mgqa']

package_data = \
{'': ['*']}

install_requires = \
['mgqa', 'torch']

setup_kwargs = {
    'name': 'mmqqa',
    'version': '0.0.5',
    'description': 'mmca-mgqa - Pytorch',
    'long_description': '[![Multi-Modality](agorabanner.png)](https://discord.gg/qUtxnK2NMf)\n\n# Multi-Modal Casual Multi-Grouped Query Attention\nExperiments around using Multi-Modal Casual Attention with Multi-Grouped Query Attention\n\n\n# Appreciation\n* Lucidrains\n* Agorians\n\n\n# Install\n`pip install mmqqa`\n\n# Usage\n```python\nimport torch \nfrom mmca_mgqa.attention import SimpleMMCA\n\n# Define the dimensions\ndim = 512\nhead = 8\nseq_len = 10\nbatch_size = 32\n\n#attn\nattn = SimpleMMCA(dim=dim, heads=head)\n\n#random tokens\nv = torch.randn(batch_size, seq_len, dim)\nt = torch.randn(batch_size, seq_len, dim)\n\n#pass the tokens throught attn\ntokens = attn(v, t)\n\nprint(tokens)\n```\n---\n\n# Architectural Overview and Analysis of Multi-Modal Causal Attention\n\nThe Multi-Modal Causal Attention (MMCA) mechanism is a novel approach to multi-modal learning that combines the strengths of causal attention and cross attention. It is designed to handle both visual and textual data, making it particularly useful for tasks that involve both types of data, such as image captioning, visual question answering, and multi-modal translation.\n\nThe MMCA mechanism is unique in its use of MultiGrouped Query Attention (MGQA), a variant of the attention mechanism that allows for more flexible and efficient attention computations. This report provides an in-depth analysis of the MMCA mechanism, focusing on its architecture, operation, and potential benefits for multi-modal learning.\n\n---\n\n## Architecture\n\nThe MMCA mechanism consists of three main components: a MGQA mechanism for visual tokens, a MGQA mechanism for textual tokens, and a cross-attention mechanism that allows textual tokens to attend to visual tokens.\n\n```\n+-----------------+     +-----------------+     +-----------------+\n| Visual Features | --> | Visual MGQA     | --> | Visual Attention|\n|                 |     |                 |     | Output          |\n+-----------------+     +-----------------+     +-----------------+\n\n+-----------------+     +-----------------+     +-----------------+     +-----------------+\n| Textual Features| --> | Textual MGQA    | --> | Textual MGQA    | --> | Textual Attention|\n|                 |     |                 |     | Output          |     | Output          |\n+-----------------+     +-----------------+     +-----------------+     +-----------------+\n\n+-----------------+     +-----------------+     +-----------------+\n| Textual MGQA    | --> | Cross-Attention | --> | Cross-Attention |\n| Output + Visual |     | with Visual     |     | Output          |\n| Attention Output|     | Attention Output|     |                 |\n+-----------------+     +-----------------+     +-----------------+\n\n```\n----\n\n## How It Works\n\nThe MMCA mechanism works by first applying MGQA to the visual and textual features separately. The MGQA mechanism is a variant of the attention mechanism that allows for more flexible and efficient attention computations. It works by dividing the queries into multiple groups and computing the attention for each group separately. This allows the model to capture different types of dependencies within the data, which can help to improve performance.\n\nFor visual tokens, the MGQA mechanism is sufficient because visual tokens are already fully encoded in a bidirectional manner and do not need further attention from other visual tokens or the beginning of textual tokens.\n\nFor textual tokens, however, the MGQA mechanism is combined with a cross-attention mechanism that allows textual tokens to attend to visual tokens. This is based on the intuition that the attention weight for one modality may affect the other modality. For instance, a textual token may pay more attention to textual information than visual information. Therefore, if the attention weight matrix is normalized across both modalities, the attention score for visual tokens might be very small.\n\nThe outputs of the MGQA and cross-attention mechanisms for the textual tokens are then combined to produce the final textual attention output. This combined attention output captures both the dependencies within the text and the dependencies between the text and the image, which can help to improve the performance of the model on multi-modal tasks.\n\n---\n\n## How It Accelerates Multi-Modal Learning\n\nThe MMCA mechanism can accelerate multi-modal learning in several ways:\n\n1.  Efficient Use of Computational Resources: By using MGQA, the MMCA mechanism can make more efficient use of computational resources. This is because MGQA allows for more flexible and efficient attention computations, which can help to reduce the computational cost of the model.\n\n2.  Improved Data Efficiency: The MMCA mechanism can improve data efficiency by allowing textual tokens to attend to visual tokens. This can help to align visual features with textual features, which can improve the performance of the model on multi-modal tasks.\n\n3.  Flexibility: The MMCA mechanism is flexible and can be easily adapted to different tasks and data types. For instance, it can be used with different types of MGQA and cross-attention mechanisms, and it can be combined with other techniques, such as pretraining, to further improve performance.\n\n4.  Scalability: The MMCA mechanism is scalable and can handle large amounts of data and complex tasks. This is because it uses a linear attention mechanism, which has a time complexity that is linear in the sequence length, making it suitable for long sequences and large datasets.\n\n\nto finally conclude the Multi-Modal Causal Attention (MMCA) mechanism is a promising approach to multi-modal learning that combines the strengths of causal attention and cross attention. By using MultiGrouped Query Attention (MGQA), it allows for more flexible and efficient attention computations, which can help to improve the performance of the model on\n\n# Todo\n\n\n# License\nMIT\n',
    'author': 'Kye Gomez',
    'author_email': 'kye@apac.ai',
    'maintainer': 'None',
    'maintainer_email': 'None',
    'url': 'https://github.com/kyegomez/mmca-mgqa',
    'packages': packages,
    'package_data': package_data,
    'install_requires': install_requires,
    'python_requires': '>=3.6,<4.0',
}


setup(**setup_kwargs)
