Sadjad Alikhani commited on
Commit
cd7cb8b
·
verified ·
1 Parent(s): f911ced

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +126 -0
README.md ADDED
@@ -0,0 +1,126 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # LWM: Large Wireless Model
2
+
3
+ This repository contains the implementation of **LWM** (Large Wireless Model), a pre-trained model for processing and extracting features from wireless communication datasets, specifically DeepMIMO. The instructions below will help you load DeepMIMO data, use the LWM model and weights, tokenize DeepMIMO scenario data, and generate either raw channels or the inferred LWM CLS or channel embeddings.
4
+
5
+ ## How to Use
6
+
7
+ ### Step-by-Step Guide
8
+
9
+ 1. **Clone the Repository**
10
+
11
+ Clone the Hugging Face repository to your local machine using the following code:
12
+
13
+ ```python
14
+ import subprocess
15
+ import os
16
+ import sys
17
+ import importlib.util
18
+ import torch
19
+
20
+ # Hugging Face public repository URL
21
+ repo_url = "https://huggingface.co/sadjadalikhani/LWM"
22
+
23
+ # Directory where the repo will be cloned
24
+ clone_dir = "./LWM"
25
+
26
+ # Step 1: Clone the repository if it hasn't been cloned already
27
+ if not os.path.exists(clone_dir):
28
+ print(f"Cloning repository from {repo_url} into {clone_dir}...")
29
+ result = subprocess.run(["git", "clone", repo_url, clone_dir], capture_output=True, text=True)
30
+
31
+ if result.returncode != 0:
32
+ print(f"Error cloning repository: {result.stderr}")
33
+ sys.exit(1) # Exit on failure
34
+ print(f"Repository cloned successfully into {clone_dir}")
35
+ else:
36
+ print(f"Repository already cloned into {clone_dir}")
37
+
38
+ # Step 2: Add the cloned directory to Python path
39
+ sys.path.append(clone_dir)
40
+
41
+ # Step 3: Dynamic module import and function exposure
42
+ def import_functions_from_file(module_name, file_path):
43
+ try:
44
+ spec = importlib.util.spec_from_file_location(module_name, file_path)
45
+ module = importlib.util.module_from_spec(spec)
46
+ spec.loader.exec_module(module)
47
+
48
+ # Extract functions from the module and make them globally accessible
49
+ for function_name in dir(module):
50
+ if callable(getattr(module, function_name)) and not function_name.startswith("__"):
51
+ globals()[function_name] = getattr(module, function_name)
52
+
53
+ return module
54
+ except FileNotFoundError:
55
+ print(f"Error: {file_path} not found!")
56
+ sys.exit(1)
57
+
58
+ # Step 4: Import necessary functions
59
+ import_functions_from_file("lwm_model", os.path.join(clone_dir, "lwm_model.py"))
60
+ import_functions_from_file("inference", os.path.join(clone_dir, "inference.py"))
61
+ import_functions_from_file("load_data", os.path.join(clone_dir, "load_data.py"))
62
+ import_functions_from_file("input_preprocess", os.path.join(clone_dir, "input_preprocess.py"))
63
+ print("All required functions imported successfully.")
64
+ ```
65
+
66
+ 2. **Load the LWM Model**
67
+
68
+ After cloning the repository, you can load the LWM model with the following code:
69
+
70
+ ```python
71
+ # Step 5: Load the LWM model (with flexibility for the device)
72
+ device = 'cuda' if torch.cuda.is_available() else 'cpu'
73
+ print(f"Loading the LWM model on {device}...")
74
+ model = LWM.from_pretrained(device=device)
75
+ ```
76
+
77
+ 3. **Load the DeepMIMO Dataset**
78
+
79
+ Load the DeepMIMO dataset with this code:
80
+
81
+ ```python
82
+ # Step 6: Load dataset (direct call, no module prefix)
83
+ print("Loading DeepMIMO dataset...")
84
+ deepmimo_data = load_DeepMIMO_data()
85
+ ```
86
+
87
+ 4. **Tokenize the DeepMIMO Dataset**
88
+
89
+ Tokenize the loaded dataset. You can choose the scenario indices to select specific scenarios from DeepMIMO:
90
+
91
+ ```python
92
+ # Step 7: Tokenize the dataset (direct call, no module prefix)
93
+ scenario_idxs = torch.arange(1) # Adjust the number of scenarios you want
94
+ print("Tokenizing the dataset...")
95
+ preprocessed_chs = tokenizer(deepmimo_data, scenario_idxs, gen_raw=True)
96
+ ```
97
+
98
+ 5. **Generate the Dataset for Inference**
99
+
100
+ Choose the type of data you want to generate from the tokenized dataset, such as `cls_emb`, `channel_emb`, or `raw`:
101
+
102
+ ```python
103
+ # Step 8: Generate the dataset for inference (direct call, no module prefix)
104
+ input_type = ['cls_emb', 'channel_emb', 'raw'][1] # Modify input type as needed
105
+ dataset = dataset_gen(preprocessed_chs, input_type, model)
106
+ ```
107
+
108
+ 6. **Print Results**
109
+
110
+ Finally, you can print the results and check the shape of the generated dataset:
111
+
112
+ ```python
113
+ # Step 9: Print results
114
+ print(f"Dataset generated with shape: {dataset.shape}")
115
+ print("Inference completed successfully.")
116
+ ```
117
+
118
+ ---
119
+
120
+ ### Requirements
121
+
122
+ - Python 3.x
123
+ - PyTorch
124
+ - Git
125
+
126
+ Ensure you have the necessary libraries installed before running the script.