




'''simple docstring'''


import math

import torch
from torch import nn

from ..configuration_utils import ConfigMixin, register_to_config
from .attention_processor import Attention
from .embeddings import get_timestep_embedding
from .modeling_utils import ModelMixin





class  __lowercase    (	__magic_name__							,				__magic_name__			):







   @register_to_config
   def __init__(						self   ,				UpperCamelCase = 128   ,				UpperCamelCase = 256   ,				UpperCamelCase = 2_000.0   ,				UpperCamelCase = 768   ,				UpperCamelCase = 12   ,				UpperCamelCase = 12   ,				UpperCamelCase = 64   ,				UpperCamelCase = 2048   ,				UpperCamelCase = 0.1   ,				)					->     int:
     super().__init__()

     __a								=       nn.Sequential(
         nn.Linear(UpperCamelCase   ,				d_model * 4   ,				bias=UpperCamelCase   )   ,				nn.SiLU()   ,				nn.Linear(d_model * 4   ,				d_model * 4   ,				bias=UpperCamelCase   )   ,				nn.SiLU()   ,				)

     __a								=       nn.Embedding(UpperCamelCase   ,				UpperCamelCase   )
     __a								=       False

     __a								=       nn.Linear(UpperCamelCase   ,				UpperCamelCase   ,				bias=UpperCamelCase   )

     __a								=       nn.Dropout(p=UpperCamelCase   )

     __a								=       nn.ModuleList()
     for lyr_num in range(UpperCamelCase   ):
       # FiLM conditional T5 decoder
       __a								=       DecoderLayer(d_model=UpperCamelCase   ,				d_kv=UpperCamelCase   ,				num_heads=UpperCamelCase   ,				d_ff=UpperCamelCase   ,				dropout_rate=UpperCamelCase   )
       self.decoders.append(UpperCamelCase   )

     __a								=       TaLayerNorm(UpperCamelCase   )

     __a								=       nn.Dropout(p=UpperCamelCase   )
     __a								=       nn.Linear(UpperCamelCase   ,				UpperCamelCase   ,				bias=UpperCamelCase   )







   def 		UpperCamelCase__      (						self   ,				UpperCamelCase   ,				UpperCamelCase   )					->     List[str]:
     __a								=       torch.mul(query_input.unsqueeze(-1   )   ,				key_input.unsqueeze(-2   )   )
     return mask.unsqueeze(-3   )







   def 		UpperCamelCase__      (						self   ,				UpperCamelCase   ,				UpperCamelCase   ,				UpperCamelCase   )					->     Any:
     __a						,							__a						,							__a								=       decoder_input_tokens.shape
     assert decoder_noise_time.shape == (batch,)

     # decoder_noise_time is in [0, 1), so rescale to expected timing range.
     __a								=       get_timestep_embedding(
         decoder_noise_time * self.config.max_decoder_noise_time   ,				embedding_dim=self.config.d_model   ,				max_period=self.config.max_decoder_noise_time   ,				).to(dtype=self.dtype   )

     __a								=       self.conditioning_emb(UpperCamelCase   ).unsqueeze(1   )

     assert conditioning_emb.shape == (batch, 1, self.config.d_model * 4)

     __a								=       decoder_input_tokens.shape[1]

     # If we want to use relative positions for audio context, we can just offset
     # this sequence by the length of encodings_and_masks.
     __a								=       torch.broadcast_to(
         torch.arange(UpperCamelCase   ,				device=decoder_input_tokens.device   )   ,				(batch, seq_length)   ,				)

     __a								=       self.position_encoding(UpperCamelCase   )

     __a								=       self.continuous_inputs_projection(UpperCamelCase   )
     inputs += position_encodings
     __a								=       self.dropout(UpperCamelCase   )

     # decoder: No padding present.
     __a								=       torch.ones(
         decoder_input_tokens.shape[:2]   ,				device=decoder_input_tokens.device   ,				dtype=inputs.dtype   )

     # Translate encoding masks to encoder-decoder masks.
     __a								=       [(x, self.encoder_decoder_mask(UpperCamelCase   ,				UpperCamelCase   )) for x, y in encodings_and_masks]

     # cross attend style: concat encodings
     __a								=       torch.cat([x[0] for x in encodings_and_encdec_masks]   ,				dim=1   )
     __a								=       torch.cat([x[1] for x in encodings_and_encdec_masks]   ,				dim=-1   )

     for lyr in self.decoders:
       __a								=       lyr(
           UpperCamelCase   ,				conditioning_emb=UpperCamelCase   ,				encoder_hidden_states=UpperCamelCase   ,				encoder_attention_mask=UpperCamelCase   ,				)[0]

     __a								=       self.decoder_norm(UpperCamelCase   )
     __a								=       self.post_dropout(UpperCamelCase   )

     __a								=       self.spec_out(UpperCamelCase   )
     return spec_out





class  __lowercase    (	nn.Module			):







   def __init__(						self   ,				UpperCamelCase   ,				UpperCamelCase   ,				UpperCamelCase   ,				UpperCamelCase   ,				UpperCamelCase   ,				UpperCamelCase=1e-6   )					->     int:
     super().__init__()
     __a								=       nn.ModuleList()

     # cond self attention: layer 0
     self.layer.append(
         TaLayerSelfAttentionCond(d_model=UpperCamelCase   ,				d_kv=UpperCamelCase   ,				num_heads=UpperCamelCase   ,				dropout_rate=UpperCamelCase   )   )

     # cross attention: layer 1
     self.layer.append(
         TaLayerCrossAttention(
             d_model=UpperCamelCase   ,				d_kv=UpperCamelCase   ,				num_heads=UpperCamelCase   ,				dropout_rate=UpperCamelCase   ,				layer_norm_epsilon=UpperCamelCase   ,				)   )

     # Film Cond MLP + dropout: last layer
     self.layer.append(
         TaLayerFFCond(d_model=UpperCamelCase   ,				d_ff=UpperCamelCase   ,				dropout_rate=UpperCamelCase   ,				layer_norm_epsilon=UpperCamelCase   )   )







   def 		UpperCamelCase__      (						self   ,				UpperCamelCase   ,				UpperCamelCase=None   ,				UpperCamelCase=None   ,				UpperCamelCase=None   ,				UpperCamelCase=None   ,				UpperCamelCase=None   ,				)					->     List[Any]:
     __a								=       self.layer[0](
         UpperCamelCase   ,				conditioning_emb=UpperCamelCase   ,				attention_mask=UpperCamelCase   ,				)

     if encoder_hidden_states is not None:
       __a								=       torch.where(encoder_attention_mask > 0   ,				0   ,				-1e10   ).to(
           encoder_hidden_states.dtype   )

       __a								=       self.layer[1](
           UpperCamelCase   ,				key_value_states=UpperCamelCase   ,				attention_mask=UpperCamelCase   ,				)

     # Apply Film Conditional Feed Forward layer
     __a								=       self.layer[-1](UpperCamelCase   ,				UpperCamelCase   )

     return (hidden_states,)





class  __lowercase    (	nn.Module			):







   def __init__(						self   ,				UpperCamelCase   ,				UpperCamelCase   ,				UpperCamelCase   ,				UpperCamelCase   )					->     Tuple:
     super().__init__()
     __a								=       TaLayerNorm(UpperCamelCase   )
     __a								=       TaFiLMLayer(in_features=d_model * 4   ,				out_features=UpperCamelCase   )
     __a								=       Attention(query_dim=UpperCamelCase   ,				heads=UpperCamelCase   ,				dim_head=UpperCamelCase   ,				out_bias=UpperCamelCase   ,				scale_qk=UpperCamelCase   )
     __a								=       nn.Dropout(UpperCamelCase   )







   def 		UpperCamelCase__      (						self   ,				UpperCamelCase   ,				UpperCamelCase=None   ,				UpperCamelCase=None   ,				)					->     Optional[Any]:
     # pre_self_attention_layer_norm
     __a								=       self.layer_norm(UpperCamelCase   )

     if conditioning_emb is not None:
       __a								=       self.FiLMLayer(UpperCamelCase   ,				UpperCamelCase   )

     # Self-attention block
     __a								=       self.attention(UpperCamelCase   )

     __a								=       hidden_states + self.dropout(UpperCamelCase   )

     return hidden_states





class  __lowercase    (	nn.Module			):







   def __init__(						self   ,				UpperCamelCase   ,				UpperCamelCase   ,				UpperCamelCase   ,				UpperCamelCase   ,				UpperCamelCase   )					->     Optional[Any]:
     super().__init__()
     __a								=       Attention(query_dim=UpperCamelCase   ,				heads=UpperCamelCase   ,				dim_head=UpperCamelCase   ,				out_bias=UpperCamelCase   ,				scale_qk=UpperCamelCase   )
     __a								=       TaLayerNorm(UpperCamelCase   ,				eps=UpperCamelCase   )
     __a								=       nn.Dropout(UpperCamelCase   )







   def 		UpperCamelCase__      (						self   ,				UpperCamelCase   ,				UpperCamelCase=None   ,				UpperCamelCase=None   ,				)					->     Optional[Any]:
     __a								=       self.layer_norm(UpperCamelCase   )
     __a								=       self.attention(
         UpperCamelCase   ,				encoder_hidden_states=UpperCamelCase   ,				attention_mask=attention_mask.squeeze(1   )   ,				)
     __a								=       hidden_states + self.dropout(UpperCamelCase   )
     return layer_output





class  __lowercase    (	nn.Module			):







   def __init__(						self   ,				UpperCamelCase   ,				UpperCamelCase   ,				UpperCamelCase   ,				UpperCamelCase   )					->     str:
     super().__init__()
     __a								=       TaDenseGatedActDense(d_model=UpperCamelCase   ,				d_ff=UpperCamelCase   ,				dropout_rate=UpperCamelCase   )
     __a								=       TaFiLMLayer(in_features=d_model * 4   ,				out_features=UpperCamelCase   )
     __a								=       TaLayerNorm(UpperCamelCase   ,				eps=UpperCamelCase   )
     __a								=       nn.Dropout(UpperCamelCase   )







   def 		UpperCamelCase__      (						self   ,				UpperCamelCase   ,				UpperCamelCase=None   )					->     Any:
     __a								=       self.layer_norm(UpperCamelCase   )
     if conditioning_emb is not None:
       __a								=       self.film(UpperCamelCase   ,				UpperCamelCase   )

     __a								=       self.DenseReluDense(UpperCamelCase   )
     __a								=       hidden_states + self.dropout(UpperCamelCase   )
     return hidden_states





class  __lowercase    (	nn.Module			):







   def __init__(						self   ,				UpperCamelCase   ,				UpperCamelCase   ,				UpperCamelCase   )					->     int:
     super().__init__()
     __a								=       nn.Linear(UpperCamelCase   ,				UpperCamelCase   ,				bias=UpperCamelCase   )
     __a								=       nn.Linear(UpperCamelCase   ,				UpperCamelCase   ,				bias=UpperCamelCase   )
     __a								=       nn.Linear(UpperCamelCase   ,				UpperCamelCase   ,				bias=UpperCamelCase   )
     __a								=       nn.Dropout(UpperCamelCase   )
     __a								=       NewGELUActivation()







   def 		UpperCamelCase__      (						self   ,				UpperCamelCase   )					->     int:
     __a								=       self.act(self.wi_a(UpperCamelCase   )   )
     __a								=       self.wi_a(UpperCamelCase   )
     __a								=       hidden_gelu * hidden_linear
     __a								=       self.dropout(UpperCamelCase   )

     __a								=       self.wo(UpperCamelCase   )
     return hidden_states





class  __lowercase    (	nn.Module			):







   def __init__(						self   ,				UpperCamelCase   ,				UpperCamelCase=1e-6   )					->     Optional[int]:
     super().__init__()
     __a								=       nn.Parameter(torch.ones(UpperCamelCase   )   )
     __a								=       eps







   def 		UpperCamelCase__      (						self   ,				UpperCamelCase   )					->     str:
     # T5 uses a layer_norm which only scales and doesn't shift, which is also known as Root Mean
     # Square Layer Normalization https://arxiv.org/abs/1910.07467 thus variance is calculated
     # w/o mean and there is no bias. Additionally we want to make sure that the accumulation for
     # half-precision inputs is done in fp32

     __a								=       hidden_states.to(torch.floataa   ).pow(2   ).mean(-1   ,				keepdim=UpperCamelCase   )
     __a								=       hidden_states * torch.rsqrt(variance + self.variance_epsilon   )

     # convert into half-precision if necessary
     if self.weight.dtype in [torch.floataa, torch.bfloataa]:
       __a								=       hidden_states.to(self.weight.dtype   )

     return self.weight * hidden_states





class  __lowercase    (	nn.Module			):







   def 		UpperCamelCase__      (						self   ,				UpperCamelCase   )					->     torch.Tensor:
     return 0.5 * input * (1.0 + torch.tanh(math.sqrt(2.0 / math.pi   ) * (input + 0.044_715 * torch.pow(UpperCamelCase   ,				3.0   ))   ))





class  __lowercase    (	nn.Module			):







   def __init__(						self   ,				UpperCamelCase   ,				UpperCamelCase   )					->     Any:
     super().__init__()
     __a								=       nn.Linear(UpperCamelCase   ,				out_features * 2   ,				bias=UpperCamelCase   )







   def 		UpperCamelCase__      (						self   ,				UpperCamelCase   ,				UpperCamelCase   )					->     Optional[Any]:
     __a								=       self.scale_bias(UpperCamelCase   )
     __a						,							__a								=       torch.chunk(UpperCamelCase   ,				2   ,				-1   )
     __a								=       x * (1 + scale) + shift
     return x









'''simple docstring'''


import gc
import random
import unittest

import numpy as np
import torch
from transformers import (
    CLIPImageProcessor,
    CLIPTextConfig,
    CLIPTextModel,
    CLIPTokenizer,
    CLIPVisionConfig,
    CLIPVisionModelWithProjection,
)

from diffusers import AutoencoderKL, DDIMScheduler, DDPMScheduler, StableUnCLIPImgaImgPipeline, UNetaDConditionModel
from diffusers.pipelines.pipeline_utils import DiffusionPipeline
from diffusers.pipelines.stable_diffusion.stable_unclip_image_normalizer import StableUnCLIPImageNormalizer
from diffusers.utils.import_utils import is_xformers_available
from diffusers.utils.testing_utils import (
    enable_full_determinism,
    floats_tensor,
    load_image,
    load_numpy,
    require_torch_gpu,
    skip_mps,
    slow,
    torch_device,
)

from ..pipeline_params import TEXT_GUIDED_IMAGE_VARIATION_BATCH_PARAMS, TEXT_GUIDED_IMAGE_VARIATION_PARAMS
from ..test_pipelines_common import (
    PipelineKarrasSchedulerTesterMixin,
    PipelineLatentTesterMixin,
    PipelineTesterMixin,
    assert_mean_pixel_difference,
)


enable_full_determinism()





class  __lowercase    (	__magic_name__							,				__magic_name__							,				__magic_name__							,				unittest.TestCase			):
   _a    						=   StableUnCLIPImgaImgPipeline
   _a    						=   TEXT_GUIDED_IMAGE_VARIATION_PARAMS
   _a    						=   TEXT_GUIDED_IMAGE_VARIATION_BATCH_PARAMS
   _a    						=   frozenset(
       []			)  # TO-DO: update image_params once pipeline is refactored with VaeImageProcessor.preprocess
   _a    						=   frozenset([]			)







   def 		UpperCamelCase__      (						self   )					->     List[str]:
     __a								=       32
     __a								=       embedder_hidden_size

     # image encoding components

     __a								=       CLIPImageProcessor(crop_size=32   ,				size=32   )

     torch.manual_seed(0   )
     __a								=       CLIPVisionModelWithProjection(
         CLIPVisionConfig(
             hidden_size=UpperCamelCase   ,				projection_dim=UpperCamelCase   ,				num_hidden_layers=5   ,				num_attention_heads=4   ,				image_size=32   ,				intermediate_size=37   ,				patch_size=1   ,				)   )

     # regular denoising components

     torch.manual_seed(0   )
     __a								=       StableUnCLIPImageNormalizer(embedding_dim=UpperCamelCase   )
     __a								=       DDPMScheduler(beta_schedule='squaredcos_cap_v2'   )

     torch.manual_seed(0   )
     __a								=       CLIPTokenizer.from_pretrained('hf-internal-testing/tiny-random-clip'   )

     torch.manual_seed(0   )
     __a								=       CLIPTextModel(
         CLIPTextConfig(
             bos_token_id=0   ,				eos_token_id=2   ,				hidden_size=UpperCamelCase   ,				projection_dim=32   ,				intermediate_size=37   ,				layer_norm_eps=1e-05   ,				num_attention_heads=4   ,				num_hidden_layers=5   ,				pad_token_id=1   ,				vocab_size=1000   ,				)   )

     torch.manual_seed(0   )
     __a								=       UNetaDConditionModel(
         sample_size=32   ,				in_channels=4   ,				out_channels=4   ,				down_block_types=('CrossAttnDownBlock2D', 'DownBlock2D')   ,				up_block_types=('UpBlock2D', 'CrossAttnUpBlock2D')   ,				block_out_channels=(32, 64)   ,				attention_head_dim=(2, 4)   ,				class_embed_type='projection'   ,				projection_class_embeddings_input_dim=embedder_projection_dim * 2   ,				cross_attention_dim=UpperCamelCase   ,				layers_per_block=1   ,				upcast_attention=UpperCamelCase   ,				use_linear_projection=UpperCamelCase   ,				)

     torch.manual_seed(0   )
     __a								=       DDIMScheduler(
         beta_schedule='scaled_linear'   ,				beta_start=0.00_085   ,				beta_end=0.012   ,				prediction_type='v_prediction'   ,				set_alpha_to_one=UpperCamelCase   ,				steps_offset=1   ,				)

     torch.manual_seed(0   )
     __a								=       AutoencoderKL()

     __a								=       {
         # image encoding components
         'feature_extractor': feature_extractor,
         'image_encoder': image_encoder.eval(),
         # image noising components
         'image_normalizer': image_normalizer.eval(),
         'image_noising_scheduler': image_noising_scheduler,
         # regular denoising components
         'tokenizer': tokenizer,
         'text_encoder': text_encoder.eval(),
         'unet': unet.eval(),
         'scheduler': scheduler,
         'vae': vae.eval(),
     }

     return components







   def 		UpperCamelCase__      (						self   ,				UpperCamelCase   ,				UpperCamelCase=0   ,				UpperCamelCase=True   )					->     Dict:
     if str(UpperCamelCase   ).startswith('mps'   ):
       __a								=       torch.manual_seed(UpperCamelCase   )
     else:
       __a								=       torch.Generator(device=UpperCamelCase   ).manual_seed(UpperCamelCase   )

     __a								=       floats_tensor((1, 3, 32, 32)   ,				rng=random.Random(UpperCamelCase   )   ).to(UpperCamelCase   )

     if pil_image:
       __a								=       input_image * 0.5 + 0.5
       __a								=       input_image.clamp(0   ,				1   )
       __a								=       input_image.cpu().permute(0   ,				2   ,				3   ,				1   ).float().numpy()
       __a								=       DiffusionPipeline.numpy_to_pil(UpperCamelCase   )[0]

     return {
         "prompt": "An anime racoon running a marathon",
         "image": input_image,
         "generator": generator,
         "num_inference_steps": 2,
         "output_type": "np",
     }







   @skip_mps
   def 		UpperCamelCase__      (						self   )					->     int:
     __a								=       'cpu'  # ensure determinism for the device-dependent torch.Generator
     __a								=       self.get_dummy_components()
     __a								=       StableUnCLIPImgaImgPipeline(**UpperCamelCase   )
     __a								=       sd_pipe.to(UpperCamelCase   )
     sd_pipe.set_progress_bar_config(disable=UpperCamelCase   )

     __a								=       self.get_dummy_inputs(UpperCamelCase   )
     inputs.update({'image_embeds': None}   )
     __a								=       sd_pipe(**UpperCamelCase   ).images
     __a								=       image[0, -3:, -3:, -1]

     assert image.shape == (1, 32, 32, 3)
     __a								=       np.array([0.3_872, 0.7_224, 0.5_601, 0.4_741, 0.6_872, 0.5_814, 0.4_636, 0.3_867, 0.5_078]   )

     assert np.abs(image_slice.flatten() - expected_slice   ).max() < 1e-3







   def 		UpperCamelCase__      (						self   )					->     Any:
     __a								=       torch_device in ['cpu', 'mps']

     self._test_attention_slicing_forward_pass(test_max_difference=UpperCamelCase   )







   def 		UpperCamelCase__      (						self   )					->     Union[str, Any]:
     __a								=       torch_device in ['cpu', 'mps']

     self._test_inference_batch_single_identical(test_max_difference=UpperCamelCase   )







   @unittest.skipIf(
       torch_device != 'cuda' or not is_xformers_available()   ,				reason='XFormers attention is only available with CUDA and `xformers` installed'   ,				)
   def 		UpperCamelCase__      (						self   )					->     Optional[Any]:
     self._test_xformers_attention_forwardGenerator_pass(test_max_difference=UpperCamelCase   )





@slow
@require_torch_gpu
class  __lowercase    (	unittest.TestCase			):







   def 		UpperCamelCase__      (						self   )					->     List[Any]:
     # clean up the VRAM after each test
     super().tearDown()
     gc.collect()
     torch.cuda.empty_cache()







   def 		UpperCamelCase__      (						self   )					->     str:
     __a								=       load_image(
         'https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/stable_unclip/turtle.png'   )

     __a								=       load_numpy(
         'https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/stable_unclip/stable_unclip_2_1_l_img2img_anime_turtle_fp16.npy'   )

     __a								=       StableUnCLIPImgaImgPipeline.from_pretrained(
         'fusing/stable-unclip-2-1-l-img2img'   ,				torch_dtype=torch.floataa   )
     pipe.to(UpperCamelCase   )
     pipe.set_progress_bar_config(disable=UpperCamelCase   )
     # stable unclip will oom when integration tests are run on a V100,
     # so turn on memory savings
     pipe.enable_attention_slicing()
     pipe.enable_sequential_cpu_offload()

     __a								=       torch.Generator(device='cpu'   ).manual_seed(0   )
     __a								=       pipe(UpperCamelCase   ,				'anime turle'   ,				generator=UpperCamelCase   ,				output_type='np'   )

     __a								=       output.images[0]

     assert image.shape == (768, 768, 3)

     assert_mean_pixel_difference(UpperCamelCase   ,				UpperCamelCase   )







   def 		UpperCamelCase__      (						self   )					->     Optional[int]:
     __a								=       load_image(
         'https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/stable_unclip/turtle.png'   )

     __a								=       load_numpy(
         'https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/stable_unclip/stable_unclip_2_1_h_img2img_anime_turtle_fp16.npy'   )

     __a								=       StableUnCLIPImgaImgPipeline.from_pretrained(
         'fusing/stable-unclip-2-1-h-img2img'   ,				torch_dtype=torch.floataa   )
     pipe.to(UpperCamelCase   )
     pipe.set_progress_bar_config(disable=UpperCamelCase   )
     # stable unclip will oom when integration tests are run on a V100,
     # so turn on memory savings
     pipe.enable_attention_slicing()
     pipe.enable_sequential_cpu_offload()

     __a								=       torch.Generator(device='cpu'   ).manual_seed(0   )
     __a								=       pipe(UpperCamelCase   ,				'anime turle'   ,				generator=UpperCamelCase   ,				output_type='np'   )

     __a								=       output.images[0]

     assert image.shape == (768, 768, 3)

     assert_mean_pixel_difference(UpperCamelCase   ,				UpperCamelCase   )







   def 		UpperCamelCase__      (						self   )					->     Union[str, Any]:
     __a								=       load_image(
         'https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/stable_unclip/turtle.png'   )

     torch.cuda.empty_cache()
     torch.cuda.reset_max_memory_allocated()
     torch.cuda.reset_peak_memory_stats()

     __a								=       StableUnCLIPImgaImgPipeline.from_pretrained(
         'fusing/stable-unclip-2-1-h-img2img'   ,				torch_dtype=torch.floataa   )
     __a								=       pipe.to(UpperCamelCase   )
     pipe.set_progress_bar_config(disable=UpperCamelCase   )
     pipe.enable_attention_slicing()
     pipe.enable_sequential_cpu_offload()

     __a								=       pipe(
         UpperCamelCase   ,				'anime turtle'   ,				num_inference_steps=2   ,				output_type='np'   ,				)

     __a								=       torch.cuda.max_memory_allocated()
     # make sure that less than 7 GB is allocated
     assert mem_bytes < 7 * 10**9



