text
stringlengths
1
93.6k
• /channel - <code>to get list of total connected channels</code>
• /broadcast - <code>to broadcast a message to all users</code>"""
STATUS_TXT = """<b><u>Cᴜʀʀᴇɴᴛ Dᴀᴛᴀʙᴀsᴇ Sᴛᴀᴛᴜs</b></u>
📑 ғɪʟᴇs sᴀᴠᴇᴅ: <code>{}</code>
👩🏻‍💻 ᴜsᴇʀs: <code>{}</code>
👥 ɢʀᴏᴜᴘs: <code>{}</code>
🗂️ ᴏᴄᴄᴜᴘɪᴇᴅ: <code>{}</code>
"""
LOG_TEXT_G = """#NewGroup
👥 ɢʀᴏᴜᴘ 👥 = {}(<code>{}</code>)
😇 ᴛᴏᴛᴀʟ ᴍᴇᴍʙᴇʀs 😇 = <code>{}</code>
💌 ᴀᴅᴅᴇᴅ ʙʏ 💌 - {}
"""
LOG_TEXT_P = """#NewUser
ɪᴅ ♥️- <code>{}</code>
ɴᴀᴍᴇ 💥- {}
"""
# <FILESEP>
# -*- encoding: utf-8 -*-
'''
@File : inference_cogview.py
@Time : 2021/10/09 19:41:58
@Author : Ming Ding
@Contact : dm18@mails.tsinghua.edu.cn
'''
# here put the import lib
import os
import sys
import math
import random
import torch
import argparse
from functools import partial
import numpy as np
from SwissArmyTransformer import get_args, get_tokenizer
from SwissArmyTransformer.model import CachedAutoregressiveModel
from SwissArmyTransformer.generation.sampling_strategies import BaseStrategy
from SwissArmyTransformer.generation.autoregressive_sampling import filling_sequence, evaluate_perplexity
from SwissArmyTransformer.generation.utils import timed_name, save_multiple_images, generate_continually
from coglm_strategy import CoglmStrategy
from icetk import icetk as tokenizer
tokenizer.add_special_tokens(['<start_of_image>', '<start_of_english>', '<start_of_chinese>'])
def get_masks_and_position_ids_coglm(seq, context_length):
tokens = seq.unsqueeze(0)
attention_mask = torch.ones((1, len(seq), len(seq)), device=tokens.device)
attention_mask.tril_()
attention_mask[..., :context_length] = 1
attention_mask.unsqueeze_(1)
position_ids = torch.zeros(len(seq), device=tokens.device, dtype=torch.long)
torch.arange(0, context_length, out=position_ids[:context_length])
torch.arange(512, 512 + len(seq) - context_length,
out=position_ids[context_length:]
)
position_ids = position_ids.unsqueeze(0)
return tokens, attention_mask, position_ids
def main(args):
model, args = InferenceModel.from_pretrained(args, 'coglm')
text_model = CachedAutoregressiveModel(args, transformer=model.transformer)
# define function for each query
query_template = args.query_template
invalid_slices = [slice(tokenizer.num_image_tokens, None)]
strategy = CoglmStrategy(invalid_slices,
temperature=args.temp_all_gen, top_k=args.topk_gen, top_k_cluster=args.temp_cluster_gen)
from sr_pipeline import SRGroup
srg = SRGroup(args)
from comp_pipeline import BaseCompletion, PatchCompletion, cord2mask
comp = PatchCompletion(model, strategy, srg, log_attention_weight=1.4)
def process(raw_text):
if args.with_id:
query_id, raw_text, image_path, x0, y0, x1, y1 = raw_text.split('\t')
else:
raw_text, image_path, x0, y0, x1, y1 = raw_text.split('\t')
print('raw text: ', raw_text)
text = query_template.format(raw_text)
seq = tokenizer.encode(text)
if len(seq) > 110:
raise ValueError('text too long.')
full_mask = cord2mask(float(x0), float(y0), float(x1), float(y1),
size=480, device=args.device)
txt_len = len(seq) - 1
seq = torch.tensor(seq, device=args.device)
imgs = comp(image_path, full_mask, seq, 4)