code: 
  
  
  
  import argparse
  import logging
  
  import numpy as np
  import torch
  
  from transformers import AutoModelForCausalLM, AutoTokenizer
  
  
  logging.basicConfig(
      format="""%(asctime)s - %(levelname)s - %(name)s - %(message)s""",
      datefmt="""%m/%d/%Y %H:%M:%S""",
      level=logging.INFO,
  )
  __lowerCamelCase  				=					logging.getLogger(__name__)
  
  
  
  
  def     UpperCAmelCase__ (							__snake_case							)   -> Any:
    np.random.seed(args.seed							)
    torch.manual_seed(args.seed							)
    if args.n_gpu > 0:
      torch.cuda.manual_seed_all(args.seed							)
  
  
  
  
  def     UpperCAmelCase__ (							)   -> Optional[Any]:
    _A           =    argparse.ArgumentParser()
    parser.add_argument(
        '''--model_name_or_path'''						,				default=__snake_case						,				type=__snake_case						,				required=__snake_case						,				)
    parser.add_argument('''--prompt'''						,				type=__snake_case						,				default=''''''							)
    parser.add_argument('''--length'''						,				type=__snake_case						,				default=20							)
    parser.add_argument('''--stop_token'''						,				type=__snake_case						,				default=__snake_case						,				help='''Token at which text generation is stopped'''							)
    parser.add_argument(
        '''--temperature'''						,				type=__snake_case						,				default=1.0						,				help='''temperature of 1.0 has no effect, lower tend toward greedy sampling'''						,				)
    parser.add_argument(
        '''--repetition_penalty'''						,				type=__snake_case						,				default=1.0						,				help='''primarily useful for CTRL model; in that case, use 1.2'''							)
    parser.add_argument('''--k'''						,				type=__snake_case						,				default=0							)
    parser.add_argument('''--penalty_alpha'''						,				type=__snake_case						,				default=0.0							)
    parser.add_argument('''--p'''						,				type=__snake_case						,				default=0.9							)
  
    parser.add_argument('''--prefix'''						,				type=__snake_case						,				default=''''''						,				help='''Text added prior to input.'''							)
    parser.add_argument('''--padding_text'''						,				type=__snake_case						,				default=''''''						,				help='''Deprecated, the use of `--prefix` is preferred.'''							)
    parser.add_argument('''--xlm_language'''						,				type=__snake_case						,				default=''''''						,				help='''Optional language when used with the XLM model.'''							)
  
    parser.add_argument('''--seed'''						,				type=__snake_case						,				default=42						,				help='''random seed for initialization'''							)
    parser.add_argument('''--no_cuda'''						,				action='''store_true'''						,				help='''Avoid using CUDA when available'''							)
    parser.add_argument(
        '''--fp16'''						,				action='''store_true'''						,				help='''Whether to use 16-bit (mixed) precision (through NVIDIA apex) instead of 32-bit'''						,				)
    _A           =    parser.parse_args()
  
    _A           =    torch.device('''cuda''' if torch.cuda.is_available() and not args.no_cuda else '''cpu'''							)
    _A           =    0 if args.no_cuda else torch.cuda.device_count()
  
    logger.warning(F'''device: {args.device}, n_gpu: {args.n_gpu}, 16-bits training: {args.fpaa}'''							)
  
    set_seed(__snake_case							)
  
    # Initialize the model and tokenizer
    _A           =    AutoTokenizer.from_pretrained(args.model_name_or_path							)
    _A           =    AutoModelForCausalLM.from_pretrained(args.model_name_or_path							)
  
    # tokenizer = GPT2Tokenizer.from_pretrained(args.model_name_or_path)
    # model = OPTForCausalLM.from_pretrained(args.model_name_or_path)
    model.to(args.device							)
  
    if args.fpaa:
      model.half()
  
    logger.info(__snake_case							)
    _A           =    args.prompt if args.prompt else input('''Model prompt >>> '''							)
  
    _A           =    tokenizer(__snake_case						,				return_tensors='''pt'''						,				add_special_tokens=__snake_case							)
    _A           =    {key: value.to(args.device							) for key, value in inputs.items()}
  
    _A           =    model.generate(
        **__snake_case						,				max_length=args.length + len(inputs['''input_ids'''][0]							)						,				penalty_alpha=args.penalty_alpha						,				top_k=args.k						,				)
  
    _A           =    []
    for generated_sequence_idx, generated_sequence in enumerate(__snake_case							):
      print(F'''=== GENERATED SEQUENCE {generated_sequence_idx + 1} ==='''							)
      _A           =    generated_sequence.tolist()
  
      # Decode text
      _A           =    tokenizer.decode(__snake_case						,				clean_up_tokenization_spaces=__snake_case						,				add_special_tokens=__snake_case							)
  
      # Remove all text after the stop token
      _A           =    text[: text.find(args.stop_token							) if args.stop_token else None]
  
      # Add the prompt at the beginning of the sequence. Remove the excess text that was used for pre-processing
      _A           =    (
          prompt_text + text[len(tokenizer.decode(inputs['''input_ids'''][0]						,				clean_up_tokenization_spaces=__snake_case							)							) :]
      )
  
      generated_sequences.append(__snake_case							)
      print(__snake_case							)
  
    return generated_sequences
  
  
  if __name__ == "__main__":
      main()
style_context: 
  
  
  
  import cva
  import numpy as np
  
  from digital_image_processing.filters.convolve import img_convolve
  from digital_image_processing.filters.sobel_filter import sobel_filter
  
  __lowerCamelCase  				=					1_8_0
  
  
  
  
  def     UpperCAmelCase__ (							__snake_case						,				__snake_case							)   -> Dict:
    _A           =    k_size // 2
    _A    ,   _A           =    np.mgrid[0 - center : k_size - center, 0 - center : k_size - center]
    _A           =    (
        1
        / (2 * np.pi * sigma)
        * np.exp(-(np.square(__snake_case							) + np.square(__snake_case							)) / (2 * np.square(__snake_case							))							)
    )
    return g
  
  
  
  
  def     UpperCAmelCase__ (							__snake_case						,				__snake_case						,				__snake_case							)   -> int:
    _A           =    np.zeros(__snake_case							)
  
    for row in range(1						,				image_shape[0] - 1							):
      for col in range(1						,				image_shape[1] - 1							):
        _A           =    gradient_direction[row, col]
  
        if (
            0 <= direction < PI / 8
            or 15 * PI / 8 <= direction <= 2 * PI
            or 7 * PI / 8 <= direction <= 9 * PI / 8
        ):
          _A           =    sobel_grad[row, col - 1]
          _A           =    sobel_grad[row, col + 1]
          if sobel_grad[row, col] >= w and sobel_grad[row, col] >= e:
            _A           =    sobel_grad[row, col]
  
        elif (
            PI / 8 <= direction < 3 * PI / 8
            or 9 * PI / 8 <= direction < 11 * PI / 8
        ):
          _A           =    sobel_grad[row + 1, col - 1]
          _A           =    sobel_grad[row - 1, col + 1]
          if sobel_grad[row, col] >= sw and sobel_grad[row, col] >= ne:
            _A           =    sobel_grad[row, col]
  
        elif (
            3 * PI / 8 <= direction < 5 * PI / 8
            or 11 * PI / 8 <= direction < 13 * PI / 8
        ):
          _A           =    sobel_grad[row - 1, col]
          _A           =    sobel_grad[row + 1, col]
          if sobel_grad[row, col] >= n and sobel_grad[row, col] >= s:
            _A           =    sobel_grad[row, col]
  
        elif (
            5 * PI / 8 <= direction < 7 * PI / 8
            or 13 * PI / 8 <= direction < 15 * PI / 8
        ):
          _A           =    sobel_grad[row - 1, col - 1]
          _A           =    sobel_grad[row + 1, col + 1]
          if sobel_grad[row, col] >= nw and sobel_grad[row, col] >= se:
            _A           =    sobel_grad[row, col]
  
    return destination
  
  
  
  
  def     UpperCAmelCase__ (							__snake_case						,				__snake_case						,				__snake_case						,				__snake_case						,				__snake_case						,				__snake_case							)   -> Optional[int]:
    for row in range(1						,				image_shape[0] - 1							):
      for col in range(1						,				image_shape[1] - 1							):
        if destination[row, col] >= threshold_high:
          _A           =    strong
        elif destination[row, col] <= threshold_low:
          _A           =    0
        else:
          _A           =    weak
  
  
  
  
  def     UpperCAmelCase__ (							__snake_case						,				__snake_case						,				__snake_case						,				__snake_case							)   -> List[Any]:
    for row in range(1						,				image_shape[0]							):
      for col in range(1						,				image_shape[1]							):
        if destination[row, col] == weak:
          if 255 in (
              destination[row, col + 1],
              destination[row, col - 1],
              destination[row - 1, col],
              destination[row + 1, col],
              destination[row - 1, col - 1],
              destination[row + 1, col - 1],
              destination[row - 1, col + 1],
              destination[row + 1, col + 1],
          ):
            _A           =    strong
          else:
            _A           =    0
  
  
  
  
  def     UpperCAmelCase__ (							__snake_case						,				__snake_case=15						,				__snake_case=30						,				__snake_case=128						,				__snake_case=255							)   -> List[Any]:
    # gaussian_filter
    _A           =    img_convolve(__snake_case						,				gen_gaussian_kernel(9						,				sigma=1.4							)							)
    # get the gradient and degree by sobel_filter
    _A    ,   _A           =    sobel_filter(__snake_case							)
    _A           =    PI + np.radadeg(__snake_case							)
  
    _A           =    suppress_non_maximum(image.shape						,				__snake_case						,				__snake_case							)
  
    detect_high_low_threshold(
        image.shape						,				__snake_case						,				__snake_case						,				__snake_case						,				__snake_case						,				__snake_case							)
  
    track_edge(image.shape						,				__snake_case						,				__snake_case						,				__snake_case							)
  
    return destination
  
  
  if __name__ == "__main__":
      # read original image in gray mode
      __lowerCamelCase  				=					cva.imread(R"""../image_data/lena.jpg""", 0)
      # canny edge detection
      __lowerCamelCase  				=					canny(lena)
      cva.imshow("""canny""", canny_destination)
      cva.waitKey(0)